Monday, June 15, 2009

php utf-8 chr() and ord() equivalents

As far as I can tell, PHP provides no built in methods of working with multi byte characters.

Here is a simple function for turning an integer value into a character:

function unichr($intval) {
return mb_convert_encoding(pack('n', $intval), 'UTF-8', 'UTF-16BE');
}

A uniord() function can be found in the comments of the PHP manual:
http://us.php.net/manual/en/function.ord.php

1 comments:

Rolf said...

You can generate unicode characters in the following fashion:
"\u2063"