Home > Backend Development > PHP Tutorial > [^a-zA-Z0-9u4e00-u9fa5s]我用这个匹配符号,php 中preg_replace总是报错,怎么破?

[^a-zA-Z0-9u4e00-u9fa5s]我用这个匹配符号,php 中preg_replace总是报错,怎么破?

WBOY
Release: 2016-06-23 13:55:31
Original
1790 people have browsed it

[^a-zA-Z0-9\u4e00-\u9fa5\s]  求大神赐教


回复讨论(解决方案)

/[^a-zA-Z0-9\x{4e00}-\x{9fa5}\s]/u
必须是 utf-8 编码的

但如果是 utf-8 编码的了,那么 \w 就已经能匹配汉字了,有何必费那事

错误信息是什么?

错误信息是什么?


我相匹配所有的符号 php 的 pre_place 不能匹配这个正则,郁闷!

header('Content-type: text/html;charset=utf-8');$s = 'asa-de+中文123';$p = '/[^a-zA-Z0-9\x{4e00}-\x{9fa5}\s]/u';echo preg_replace($p, '', $s); //asade中文123echo preg_replace('/[^\w\s]/u', '', $s); //asade中文123
Copy after login
Copy after login

错误信息是什么?

WARNING: PREG_MATCH_ALL() [FUNCTION.PREG-MATCH-ALL]: COMPILATION FAILED: PCRE DOES NOT SUPPORT \L, \L, \N{NAME}, \U, OR \U AT OFFSET 15 IN C:\WAMP\WWW\INDEX_MULTI.PHP ON

header('Content-type: text/html;charset=utf-8');$s = 'asa-de+中文123';$p = '/[^a-zA-Z0-9\x{4e00}-\x{9fa5}\s]/u';echo preg_replace($p, '', $s); //asade中文123echo preg_replace('/[^\w\s]/u', '', $s); //asade中文123
Copy after login
Copy after login

虽然还是不知道我错在哪了 我用工具匹配还是可以的 ,但是你的方法成功了,没有错误,学习了 ,感谢

当目前为止,php 的正则还不支持 \u4e00 这样的表述
所以你没有错,错在 php

当目前为止,php 的正则还不支持 \u4e00 这样的表述
所以你没有错,错在 php

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template