Php Chinese characters are converted into binary-decimal hexadecimal numbers & lt ;? Php *** converts a Chinese character to a unicode universal function, independent of any library, and other user-defined functions, but conditional: the input parameters of this file and the function should be UTF-8 encoded. otherwise, function conversion is required. * In fact, reverse conversion functions can also be easily compiled, not limited to Chinese characters, strange why PHP does not have a ready-made function * @ authorxieye php converts Chinese characters to binary-decimal hexadecimal numbers
"; Echo" good ". getUnicodeFromOneUTF8 (" good "); echo"
"; Echo" Hello ". getUnicodeFromOneUTF8 (" Hello "); echo"
"; Echo" how are you ". getUnicodeFromOneUTF8 (""); 20320 4.4.21952182258e + 21 */function getUnicodeFromOneUTF8 ($ word) {// Obtain the internal array representation of its characters, therefore, this file uses UTF-8 encoding! If (is_array ($ word) $ arr = $ word; else $ arr = str_split ($ word); // at this time, $ arr should be similar to array (228,189,160) // define an empty string to store $ bin_str = ''; // Convert it to a number, convert it to a binary string, and then combine it. Foreach ($ arr as $ value) $ bin_str. = decbin (ord ($ value); // at this time, $ bin_str should be similar to 111001001011110110100000. if it is a Chinese character "you" // regular cut $ bin_str = preg_replace ('/^. {4 }(. {4 }). {2 }(. {6 }). {2 }(. {6}) $/',' $1 $2 $ 3', $ bin_str); // at this time, $ bin_str should be similar to 0100111101100000, if it is a Chinese character "you" return bindec ($ bin_str); // return something similar to 20320, Chinese character "you" // return dechex (bindec ($ bin_str )); // If you want to return the hexadecimal 4f60, use this sentence} echo "you ". getUnicodeFromOneUTF8 ("you"); echo"
"; Echo" good ". getUnicodeFromOneUTF8 (" good "); echo"
"; Echo" Hello ". getUnicodeFromOneUTF8 (" Hello "); echo"
"; Echo" ". getUnicodeFromOneUTF8 (" "); exit;?>
?