Home >Backend Development >PHP Tutorial >Correct PHP matching UTF-8 Chinese regular expression_PHP tutorial
This article mainly introduces the correct PHP matching UTF-8 Chinese regular expression. This article provides a comparison There are two different regular expressions. Friends who need them can refer to them
I have been using this before
The code is as follows:
preg_match('~[x7f-xff] ~is', $string, $tmp);
I just discovered today that the above will also match characters from some European countries
You should use the following one, pay attention to the modifier u
The code is as follows:
preg_match('~[x{4e00}-x{9fa5}] ~u', $string, $tmp);