Reply to Re: Convert text

Your name:

Reply:


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&#7873;n V&#224; Bi&#7875;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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация