Unicode character in PHP string
Because JSON directly supports the \uxxxx
syntax the first thing that comes into my mind is:
$unicodeChar = '\u1000';
echo json_decode('"'.$unicodeChar.'"');
Another option would be to use mb_convert_encoding()
echo mb_convert_encoding('က', 'UTF-8', 'HTML-ENTITIES');
or make use of the direct mapping between UTF-16BE (big endian) and the Unicode codepoint:
echo mb_convert_encoding("\x10\x00", 'UTF-8', 'UTF-16BE');
Check unicode in PHP
Actually you don't even need the mb_string extension:
if (strlen($string) != strlen(utf8_decode($string)))
{
echo 'is unicode';
}
And to find the code point of a given character:
$ord = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8'));
echo $ord[1];
convert any string or a character in php to unicode code points
Use this function
function Unicode_decode($text) {
return implode(unpack('H*', iconv("UTF-8", "UCS-4BE", $text)));
}
If you want to have U+0000
use this :
for ($i=0; $i < strlen($word); $i++)
{
$wordConvert = Unicode_decode($word[$i]);
$result .= "U+" . substr($wordConvert, -4, 4) . "<br/>";
}
echo $result;
Print Unicode characters PHP
It looks like you have UTF-8 encoded strings internally, PHP outputs them properly, but your browser fails to auto-detect the encoding (it decides for ISO 8859-1 or some other encoding).
The best way is to tell the browser that UTF-8 is being used by sending the corresponding HTTP header:
header("content-type: text/html; charset=UTF-8");
Then, you can leave the rest of your code as-is and don't have to html-encode entities or create other mess.
If you want, you can additionally declare the encoding in the generated HTML by using the <meta>
tag:
<meta http-equiv=Content-Type content="text/html; charset=UTF-8">
for HTML <=4.01<meta charset="UTF-8">
for HTML5
HTTP header has priority over the <meta>
tag, but the latter may be useful if the HTML is saved to HD and then read locally.
What is the best way to replace unicode characters in a php string?
After following the lead from https://stackoverflow.com/users/395384/epb I used json_decode to translate the unicode which works.
$unicode = json_decode("\u00fc\u00be\u008c\u00a3\u00a4\u00bc") ;
$column = str_replace($unicode, "'", urldecode($row[$columnIndex]));
Why does php strpos() sometimes does not work on Unicode character?
Use:
$foo = hebrev($product->get_name());
$bar = hebrev("סט");
strpos($foo,$bar);
convert decimal value to unicode characters in php
While eval
is generally to be avoided, it seems strictly-controlled enough to be fine here.
echo eval(sprintf('return "\u{%x}";',$val));
Related Topics
Failed to Connect to Mailserver At "Localhost" Port 25
Send JavaScript Variable to PHP Variable
Highlight Row When the Checkbox Is True
Convert a Series of Parent-Child Relationships into a Hierarchical Tree
How to Store Repeating Dates Keeping in Mind Daylight Savings Time
Generating Random Results by Weight in PHP
Giving My Function Access to Outside Variable
Prevent Direct Access to a PHP Include File
How to Find the Last Day of the Month from Date
How to Flush Output After Each 'Echo' Call
How to Sort an Array of Associative Arrays by Value of a Given Key in PHP
Reference: Why Are My "Special" Unicode Characters Encoded Weird Using Json_Encode
Using Jquery $.Ajax to Call a PHP Function
What Are the PHP Operators "" and ":" Called and What Do They Do