A common function that converts a Chinese character to Unicode, does not rely on any library, and other custom functions, but conditionally: this file and the input parameters of the function should be encoded with utf-8, or the conversion of functions should be added.
.
/**
* A common function that converts a Chinese character to Unicode, does not rely on any library, and other custom functions, but conditional
* Conditions: This file and the input parameters of the function should be encoded with utf-8, or add function conversion
* In fact, can easily write a function of reverse conversion, not even limited to Chinese characters, strange why PHP does not have a ready-made function
* @author xieye
*
* @param {string} $word must be a Chinese character, or an array representing Chinese characters (with Str_ Split-cut)
* @return {string} A decimal Unicode code, such as 4f60, representing the Chinese character "you"
/
Function getUnicodeFromOneUTF8 ($word) {
// Gets the internal array representation of its characters, so this file applies utf-8 encoding!
if (Is_array ($word))
$arr = $word;
Else
$arr = Str_split ($word);
//At this point, $arr should be similar to array (228, 189, 160)
//define an empty string store
$bin _str = ';
//convert numbers to binary strings and finally unite.
foreach ($arr as $value)
$bin _str. = Decbin (ord ($value));
//At this point, $bin _str should be similar to 111001001011110110100000, if it is the Chinese character "you"
//Regular intercept
$bin _str = preg_replace ('/^.{ 4} (. { 4}). {2} (. {6}). {2} (. {6}) $/', ' {GetProperty (Content)}$2$3 ', $bin _str);
//At this point, the $bin _str should be similar to 0100111101100000, if it is the Chinese character "you"
Return Bindec ($bin _str);//back to similar 20320, kanji "You"
//return Dechex ( Bindec ($bin _str)); To return to hexadecimal 4f60, use this
}