简体   繁体   English

preg_match条件问题

[英]preg_match condition problem

I wan't to check if a string ($nick_2) got " or ñ 我不会检查字符串($ nick_2)是否为“或ñ

Is this correct? 这个对吗? i can't make it work 我不能使它工作

if ( (strlen($nick_2) >= 3) && (strlen($nick_2) <= 25) && (!preg_match("/\"/", $nick_2)) && (!preg_match("/ñ/", strtolower($nick_2))) ) {

For finding single characters, regexes are massive overkill. 对于查找单个字符,正则表达式会产生极大的过大杀伤力。 Just use 只需使用

if ((strpos('"', $nick_2) !== FALSE) || (strpos('ñ', $nick_2) !== FALSE)) {
   ... chars were found
}

Possibly your string is in UTF-8, in which case, you must use the u modifier in preg_match and should submit your expression to that function also in UTF-8. 可能您的字符串位于UTF-8中,在这种情况下,您必须在preg_match使用u修饰符,并且还应该在UTF-8中将表达式提交给该函数。

If that's the case, you will also want to do some of these things: 如果是这种情况,您还需要做以下一些事情:

  • Replace strtolower and strlen with mb_ alternatives. mb_替代替换strtolowerstrlen
  • Normalize the input. 标准化输入。
  • Check if the graphemes where those characters are don't have more code points. 检查那些字符所在的字素是否没有更多的代码点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM