Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 11 in

PHP 7.3.x,7.4.x及以上版本,短横线校验更加严格了。如果在 [] 中挂号中 - 仅表示匹配 - 字符,那么,在正则表达式中-必须添加转义\-
报错信息:

Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 11 in /home/www/home.php on line 127

常见的几种报错的可能有:

[\s-]

[\w-]

[\d-]

正确的写法:

[\s\-]

[\w\-]

[\d\-]

提示:
如果短横线在匹配区间的开头,如:[-\d] 不会报错。

随机文章:

1、CSS样式表设计的十条技巧
https://www.onexin.net/ten-css-style-sheet-design-skills/

2、Centos 6.0 下LAMP环境搭建从入门到精通(yum命令)
https://www.onexin.net/centos-6-0-under-the-lamp-environment-to-build-from-the-entry-to-the-master-yum-command/

3、自动获取“省-市-县-乡镇”地址 For UCH 2.0
https://www.onexin.net/automatically-selects-the-province-city-county-township-address/

4、Android手机试机指令
https://www.onexin.net/android-phone-test-machine-instruction/

5、Discuz!Q 如何基于 Laravel Valet 运行 Discuz! Q ?
https://www.onexin.net/discuzq-laravel-valet-discuz-q/

转载请注明出处:https://www.onexin.net/warning-preg_match_all-compilation-failed-invalid-range/

Leave a Reply