Possible Duplicate:
How to get code point number for a given character in a utf-8 string?
I have a sample code in javascript:
var str = "HELLO WORLD";
var n = str.charCodeAt(0);
This returns 72
How do I make this done in PHP?
To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X. For more Unicode character codes, see Unicode character code charts by script.
PHP does not offer native Unicode support. PHP only supports a 256-character set. However, PHP provides the UTF-8 functions utf8_encode() and utf8_decode() to provide some basic Unicode functionality. See the PHP manual for strings for more details about PHP and Unicode.
The ord() function is a inbuilt function in PHP that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string. Parameter: This function accepts a single parameter $string.
ASCII
This will help:
//Code to Character
echo chr(65);
//Character to Code
echo ord('A');
Unicode
But since these function work for ASCII, for Unicode:
function uniord($u) {
$k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
$k1 = ord(substr($k, 0, 1));
$k2 = ord(substr($k, 1, 1));
return $k2 * 256 + $k1;
}
echo uniord('ب');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With