Recently, cross-platform implementation is required. The project uses UTF-8 encoding because of various encoding problems during the operation, therefore, UTF-8 encoding is converted into unicode encoding that enables cross-language and cross-platform text conversion and processing by computers. Recently, cross-platform implementation is required. The project uses UTF-8 encoding because of various encoding problems during the operation, therefore, UTF-8 encoding is converted into unicode encoding that enables cross-language and cross-platform text conversion and processing by computers.
Script ec (2); script
For this problem, we can directly use the code. Let's use it directly. Don't thank me.
| 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 ); } |