This article mainly introduces how to use php to convert UTF-8 to unicode functions. If you need such functions, you can refer to the code below.
Provide code first:
The 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] % 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
}
} //
Return implode ("", $ unicode );
}