Home  >  Article  >  Backend Development  >  请问正则匹配,有个小疑惑

请问正则匹配,有个小疑惑

WBOY
WBOYOriginal
2016-06-13 12:01:30780browse

请教正则匹配,有个小疑惑

<br /><?php<br />$str='唐老鸭'; //老,唐老鸭等有老字的都不能通过<br />$pre='/[\'\"\ \ ]/'; //把全角空格去掉就可以<br />if(preg_match($pre, $str)){<br />	echo $str.'不通过';<br />}<br />else{<br />	echo $str.'通过';<br />}<br />?><br />

求解,谢谢。
------解决方案--------------------
指定一下编码
$pre='/[\'\"\ \ ]/u';

------解决方案--------------------
$str='唐老鸭'; <br />$pre='/[\'\"\ \ ]/';<br />if(preg_match($pre, $str)){<br />    echo $str.'不通过';<br />}<br />else{<br />    echo $str.'通过';<br />}
唐老鸭通过
$str='唐老 鸭'; <br />$pre='/[\'\"\ \ ]/';<br />if(preg_match($pre, $str)){<br />    echo $str.'不通过';<br />}<br />else{<br />    echo $str.'通过';<br />}
唐老 鸭不通过

不知道你要做什么

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