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] 不会报错。

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

随机文章:

1、WordPress shortcuts keyboard
https://www.onexin.net/wordpress-shortcuts-keyboard/

2、Laravel 8.x 简体中文最新手册指南 – 安装
https://www.onexin.net/laravel-8-x-docs-installation/

3、IIS 服务器用命令杀死进程PID
https://www.onexin.net/with-the-command-to-kill-the-process/

4、Memcache安装配置优化篇
https://www.onexin.net/memcache-installation-and-configuration-optimization-articles/

5、android的odex是什么文件
https://www.onexin.net/what-is-the-androids-odex-file/

Leave a Reply