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、Struts 2 安全漏洞层出不穷为哪般?
https://www.onexin.net/struts-2-security-vulnerabilities-endless-sorts/

2、Google Chrome 28正式发布:采用全新引擎Blink
https://www.onexin.net/chrome-28-released-the-new-engine-blink/

3、DIV+CSS布局解决IE6、IE7、IE8样式不兼容问题
https://www.onexin.net/divcss-layout-solution-ie6-ie7-ie8-style-incompatibility-issues/

4、nginx rewrite 参考资料
https://www.onexin.net/nginx-rewrite-references/

5、UCenter Home常用sql语句入门篇(一)
https://www.onexin.net/used-sql-statement-ucenter-home-getting-started-chapter/

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

Leave a Reply

Your email address will not be published. Required fields are marked *