michaelfox + utf8   14

unicode decode — Gist
<?php
function uniDecode($str,$charcode){
$text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",'toUtf8',$str);
return mb_convert_encoding($text, $charcode, 'utf-8');
}
function toUtf8($ar){
$c = null;
foreach($ar as $val){
$val = intval(substr($val,2),16);
if($val < 0x7F){ // 0000-007F
$c .= chr($val);
}elseif($val < 0x800) { // 0080-0800
$c .= chr(0xC0 | ($val / 64));
$c .= chr(0x80 | ($val % 64));
}else{ // 0800-FFFF
$c .= chr(0xE0 | (($val / 64) / 64));
$c .= chr(0x80 | (($val / 64) % 64));
$c .= chr(0x80 | ($val % 64));
}
}
return $c;
}
php  utf8  unicode  charset 
march 2011 by michaelfox

Copy this bookmark:



description:


tags: