更新时间:2023-02-21 11:46:49
在检查字符串之前,请勿使用htmlentities
,您可以在之后使用它.
You should not use htmlentities
before checking your strings, you may use it after.
如果将$name = htmlentities($name, ENT_QUOTES, "UTF-8");
应用于some'name
,它将变为some'name
.
If you apply $name = htmlentities($name, ENT_QUOTES, "UTF-8");
to some'name
, it will turn into some'name
.
此外,要缩短图案,请使用
Also, to shorten the pattern, use
preg_match("/^[A-Z'-]{2,50}$/i", $name)
/i
不区分大小写的修饰符将使整个模式不区分大小写,而[A-Z]
将匹配所有大小写的ASCII字母.
The /i
case insensitive modifier will make the whole pattern case insensitive, and [A-Z]
will match all upper- and lowercase ASCII letters.