Posted by ngocviet on 07/02/06 03:21
Thanks Kimmo Laine!
It solves my problem!
Code:
function unichr($dec)
{
if ($dec < 128) {
$utf = chr($dec);
} else if ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
} else {
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
return $utf;
}
$str = "Thuyền Và Biển";
$str = preg_replace("/&#(\d{2,5});/e", "unichr($1);", $str);
echo $str;
Kimmo Laine wrote:
> There's a solution for that at php.net
>
> http://fi.php.net/manual/en/function.chr.php#55978
>
> chr seems to be ASCII-only (which is kinda stupid if you think about it,
> plenty of utf implementations these days) but "grey" had written a
> workaround for it.
>
>
> --
> "ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
> spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
[Back to original message]
|