我们有这段代码:
$value = preg_replace("/[^\w]/", '', $value);
其中 $value
是 utf-8。在这个转换之后,多字节字符的第一个字节被剥离。如何让\w 完全覆盖 UTF-8 字符?
对不起,我的PHP不是很好
最佳答案
你可以 try with the /u modifier :
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.
如果不行,试试
-
mb_ereg_replace
- 用多字节支持替换正则表达式
相反。
关于php - PHP preg_replace 中的\w 仅覆盖 UTF-8 字符的第二个字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2553150/