Example
The code is as follows: |
Copy code |
Echo (mb_eregi ("[x80-xff].", "medium d ")? "Yes": "No"). "Chinese characters "; Echo (mb_eregi ("^ ([x80-xff].) + $", "Chinese ")? "All Chinese characters": ""); use a function to judge all Chinese characters. |
The following uses PHP as an example for matching:
The code is as follows: |
Copy code |
<? Php $ Str = "learning php is a pleasure. "; Preg_match_all ("/[x80-xff] +/", $ str, $ match ); // UTF-8 use: // Preg_match_all ("/[x {4e00}-x {9fa5}] +/u", $ str, $ match ); Print_r ($ match ); ?> Output: Array ( [0] => Array ( [0] => Learning [1] => is a happy thing. ) ) |
Regular Chinese characters
The code is as follows: |
Copy code |
$ Str = "how does php eregi match Chinese characters "; If (preg_match ("/^ [". chr (0x80). "-". chr (0xff). "] + $/", $ str )){ Echo "this is a pure Chinese string "; } Else { Echo "this is not a pure Chinese string "; } Preg_match_all ($ pat ,......) And preg_replace ($ pat ,......)...... |
Preg_match_all ("/(Chinese characters) +/ism", "I am a Chinese character, see what you think of me! ", $ M_a );
After the beginning and end of each encoding's high and low levels, you can naturally write regular expressions and directly use sixteen digits. What are the difficulties? Haha. Note that in php, the sixteen bits use x
We can also use this regular expression to determine whether it is a gb2312 Chinese character.
The code is as follows: |
Copy code |
<? Php $ Str = "example "; If (preg_match ("/^ [xb0-xf7] [xa0-xfe] + $/", $ str )){ Print ($ str. "all Chinese characters are true "); } Else { Print ($ str. "this tc is not all Chinese characters "); } ?> |