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
andstrlen
withmb_
alternatives. - Normalize the input.
- Check if the graphemes where those characters are don't have more code points.
精彩评论