note 99182 deleted from function.utf8-decode by danbrown
| From: | danbrown@php.net | Date: | Sun, 01 Aug 2010 13:56:50 +0000 |
| Subject: | note 99182 deleted from function.utf8-decode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171301@lists.php.net to get a copy of this message | ||
Note Submitter: anonymous
----
function charset_decode_utf_8($string) {
/* modification of charset_decode_utf_8
// use preg instead of ereg
// 4 bytes are also decoded
128 200 10000000 , 240 360 11110000 224 340 11100000 128 200 10000000
255 377 11111111 , 247 367 11110111 239 357 11101111 191 277 10111111
*/
if (!preg_match("/[\200-\377]/", $string)) return $string; // ereg
$string = preg_replace(
"/([\360-\367])([\200-\277])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')-240)*262144 + (ord('\\2')-128)*4096 +
(ord('\\3')-128)*64 + (ord('\\4')-128)).';'", $string);
$string = preg_replace(
"/([\340-\357])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 +
(ord('\\3')-128)).';'", $string);
$string = preg_replace(
"/([\300-\337])([\200-\277])/e",
"'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",$string);
return $string;
}
$tab=array('$','é','â¬', 'ð¤¢'); //,$pangramme);
foreach($tab as $k1 => $v1){
$ht1.='<p><span style="font-size:60px;">' . $v1 . ' = ' .
charset_decode_utf_8($v1) . ' </span>' .
strlen($v1) . ' bytes , ' . '' .
str_replace('&','&',charset_decode_utf_8($v1)) . '' .
'</p>'."\r\n" ;
}
echo $ht1;