$str = '中華人民共和國(guó)123456789abcdefg';
echo preg_match("/^[/u4e00-/u9fa5_a-za-z0-9]{3,15}$",$strname);
運(yùn)行一下上面這段代碼,看會(huì)有什么提示信息?
warning: preg_match(): compilation failed: pcre does not support /l, /l, /n, /p, /p, /u, /u, or /x at offset 3 in f:/wwwroot/php/test.php on line 2
原來(lái),php正則表達(dá)式中不支持下列 perl 轉(zhuǎn)義序列:/l, /l, /n, /p, /p, /u, /u, or /x
在 utf-8 模式下,允許用“/x{...}”,花括號(hào)中的內(nèi)容是表示十六進(jìn)制數(shù)字的字符串。原來(lái)的十六進(jìn)制轉(zhuǎn)義序列 /xhh 如果其值大于 127 的話則匹配了一個(gè)雙字節(jié) utf-8 字符。
所以,可以這樣來(lái)解決preg_match("/^[/x80-/xff_a-za-z0-9]{3,15}$",$strname);
新聞熱點(diǎn)
疑難解答