function UTF8ToEntities($string){
if (!ereg("[\200-\237]",$string) && !ereg("[\241-\377]",$string))
return $string;
$string = preg_replace("/[\302-\375]([\001-\177])/","�\\1",$string);
$string = preg_replace("/[\340-\375].([\001-\177])/","�\\1",$string);
$string = preg_replace("/[\360-\375]..([\001-\177])/","�\\1",$string);
$string = preg_replace("/[\370-\375]...([\001-\177])/","�\\1",$string);
$string = preg_replace("/[\374-\375]....([\001-\177])/","�\\1",$string);
$string = preg_replace("/[\300-\301]./", "�", $string);
$string = preg_replace("/\364[\220-\277]../","�",$string);
$string = preg_replace("/[\365-\367].../","�",$string);
$string = preg_replace("/[\370-\373]..../","�",$string);
$string = preg_replace("/[\374-\375]...../","�",$string);
$string = preg_replace("/[\376-\377]/","�",$string);
$string = preg_replace("/[\302-\364]{2,}/","�",$string);
$string = preg_replace(
"/([\360-\364])([\200-\277])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')&7)<<18 | (ord('\\2')&63)<<12 |".
" (ord('\\3')&63)<<6 | (ord('\\4')&63)).';'",
$string);
$string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')&15)<<12 | (ord('\\2')&63)<<6 | (ord('\\3')&63)).';'",
$string);
$string = preg_replace("/([\300-\337])([\200-\277])/e",
"'&#'.((ord('\\1')&31)<<6 | (ord('\\2')&63)).';'",
$string);
$string = preg_replace("/[\200-\277]/","�",$string);
return $string;
}
Tidak ada komentar:
Posting Komentar