代码高亮插件Crayon Syntax Highlighter在PHP7.4报错解决办法

在新版的WordPress中,系统已经多次提示升级PHP,考虑到新版本更高效更安全,所以决定升级。

可是,升级完成后,网站出现大量报错,报错信息如下:

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/wwwroot/www.pingzz.com/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

如果上面的代码不直观的话,可以看下图,满屏的报错。

代码高亮插件Crayon Syntax Highlighter在PHP7.4报错解决办法

可以很直观的看出错误是来自一款叫Crayon Syntax Highlighter代码高亮插件,在7.1等版本中并没有这个报错,显而易见的是,肯定是新版本语法或表达的变化造成的报错。

解决的办法也很简单,找到报错的文件与行数,进行修改即可,报错的文件是crayon_langs.class.php的340行。

代码高亮插件Crayon Syntax Highlighter在PHP7.4报错解决办法

一般我们可以通过更新插件能适配到最新版的wordpress和PHP,但遗憾的是:

代码高亮插件Crayon Syntax Highlighter在PHP7.4报错解决办法

这款插件已经于4年前停止更新了,所以我们需要自己解决,解决的方法很简单:

修改这行代码为下方即可解决该报错信息。

return preg_replace('/\[^\w-+#]/msi', '', $id);

即加上转义符好就能解决。

原创文章,作者:蓝洛水深,如若转载,请注明出处:https://www.ilanluo.com/9203

发表评论

登录后才能评论