PHP utf-8 to Unicode,phputf-8 to Unicode
Public functionUtf8_unicode ($str) { $unicode=Array(); $values=Array(); $lookingFor= 1; for($i= 0;$i<strlen($str);$i++ ) { $thisValue=Ord($str[$i ] ); if($thisValue<Ord(' A ') ) { //Exclude 0-9 if($thisValue>=Ord(' 0 ') &&$thisValue<=Ord(' 9 ')) { // Number $unicode[] =CHR($thisValue); } Else { $unicode[] = '%'.Dechex($thisValue); } } Else { if($thisValue< 128) { $unicode[] =$str[$i ]; } Else { if(Count($values) = = 0 ) { $lookingFor= ($thisValue< 224)? 2:3; } $values[] =$thisValue; if(Count($values) ==$lookingFor ) { $number= ($lookingFor= = 3)? ( ( $values[0]% 16) * 4096) + (($values[1]% 64) * 64) + ($values[2]% 64): ( ( $values[0]% 32) * 64) + ($values[1]% 64 ); $number=Dechex($number); $unicode[] = (strlen($number) ==3)? " \u0 ".$number: "\u".$number; $values=Array(); $lookingFor= 1; } //if}//if } } // for return implode("",$unicode);}
Reference article: Http://randomchaos.com/documents/?source=php_and_unicode
http://www.bkjia.com/PHPjc/924849.html www.bkjia.com true http://www.bkjia.com/PHPjc/924849.html techarticle php utf-8 to Unicode,phputf-8 to Unicode public function Utf8_unicode ($str) {$unicode = array (); $values = Array (); $l Ookingfor = 1; for ($i = 0; $i strlen ($STR); $i + + ...