PHP implementation Utf-8 to Unicode function sharing, Utf-8unicode
The code is very simple, the function is very practical, recommend to everybody.
The Code First:
Copy CodeThe code is as follows:
Public Function Utf8_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]%) * 4096) + (($values [1]% *) + ($values [2]% 64):
(($values [0]%) * + ($values [1]% 64);
$number = Dechex ($number);
$unicode [] = (strlen ($number) ==3)? " \u0 ". $number:" \u ". $number;
$values = Array ();
$lookingFor = 1;
}//If
}//If
}
}//For
Return implode ("", $unicode);
}
http://www.bkjia.com/PHPjc/938848.html www.bkjia.com true http://www.bkjia.com/PHPjc/938848.html techarticle PHP Implementation Utf-8 to Unicode function sharing, Utf-8unicode code is very simple, functional but very practical, recommended to everyone. In the code first: Copy the Code code as follows: Public function Utf8_uni ...