php tutorial match the regular expression of Chinese characters
Regular expression matching Chinese characters: [u4e00-u9fa5]
Commentary: Matching Chinese is really a headache, with this expression is easy to match the double-byte characters (including Chinese characters included): [^ x00-xff]
Commentary: Can be used to calculate the length of a string (a double-byte character length meter 2, ascii character meter 1)
* /
$ str = "singlepoint single point log";
if (preg_match ("/ ^ [x {4e00} -x {9fa5}] + $ / u", $ str)) {
print ("This string is all Chinese");
} else {
print ("This string is not all Chinese");
}
$ alias_len = mb_strlen ($ value ['alias'], "utf-8");
$ temp_array = array ();
for ($ i = 0; $ i <$ alias_len; $ i ++)
{
$ temp_array [$ i] = mb_substr ($ value ['alias'], $ i, 1, "utf-8");
if (ord (substr ($ temp_array [$ i], 0,1))> '0xe0' && strlen ($ temp_array [$ i]) <3)
$ temp_array [$ i] = '';
}
$ value ['alias'] = implode ('', $ temp_array);