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、Docking boxes 实现块拖拽移动收缩的JS
https://www.onexin.net/resource/docking-boxes-to-achieve-drag-mobile-contraction-js-block/

2、JS实现的滑动展开与折叠效果
https://www.onexin.net/latest/js-to-achieve-the-sliding-expand-and-collapse-results/

3、MySQL数thread_cache和table_cache详解
https://www.onexin.net/database/the-mysql-the-number-thread_cache-and-table_cache-xiangjie/

4、Memcache类使用方法及参数详解
https://www.onexin.net/labs/memcache-class-uses-methods-and-arguments-detailed/

5、使用ie7.js来解决ie6兼容问题
https://www.onexin.net/labs/use-ie7-js-to-solve-the-problem-of-ie6-compatible/

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

Leave a Reply

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