Home  >  Article  >  Backend Development  >  [^a-zA-Z0-9u4e00-u9fa5s]小弟我用这个匹配符号,php 中preg_replace总是报错,如何破

[^a-zA-Z0-9u4e00-u9fa5s]小弟我用这个匹配符号,php 中preg_replace总是报错,如何破

WBOY
WBOYOriginal
2016-06-13 11:59:331157browse

[^a-zA-Z0-9\u4e00-\u9fa5\s]我用这个匹配符号,php 中preg_replace总是报错,怎么破?
[^a-zA-Z0-9\u4e00-\u9fa5\s]  求大神赐教
------解决方案--------------------

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


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

Statement:
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