开发者

preg_match condition problem

开发者 https://www.devze.com 2023-03-26 12:25 出处:网络
I wan\'t to check if a stri开发者_Python百科ng ($nick_2) got \" or ñ Is this correct? i can\'t make it work

I wan't to check if a stri开发者_Python百科ng ($nick_2) got " or ñ

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.

If that's the case, you will also want to do some of these things:

  • Replace strtolower and strlen with mb_ alternatives.
  • Normalize the input.
  • Check if the graphemes where those characters are don't have more code points.
0

精彩评论

暂无评论...
验证码 换一张
取 消