且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 5.2 preg_match()编译失败

更新时间:2021-12-17 14:42:04

您需要转义 - 它与字符类有特殊的意义,因为错误消息提示。在减号前使用反斜杠:

You need to escape the - minus. It has special meaning with character classes, as the error message hints. Use a backslash before the minus:

preg_match('/[^a-zA-Z0-9_\-.]/'

(或者 - 字符组中的第一个或最后一个事物,因此它失去其特殊功能。)

(Alternatively the - may be the first or last thing in the character group, so it loses its special function.)