WP插件CodeColorer兼容PHP7
2023-02-18 16:44:23 时间
本文参考官方文档 PHP7/preg_replace函数 请定位codecolorer代码插件编辑界面并定位codecolorer/codecolorer-core.php文件修改4段代码
修改代码片段 1
$content = preg_replace('#(\\s*)\\[cc([^\\s\\]_]*(?:_[^\\s\\]]*)?)([^\\]]*)\\](.*?)\\[/cc\\2\\](\\s*)#sie', '$this->PerformHighlightCodeBlock(\\'\\\\4\\', \\'\\\\3\\', $content, \\'\\\\2\\', \\'\\\\1\\', \\'\\\\5\\');', $content);
$content = preg_replace('#(\\s*)\\<code(.*?)\\>(.*?)\\(\\s*)#sie', '$this->PerformHighlightCodeBlock(\\'\\\\3\\', \\'\\\\2\\', $content, \\'\\', \\'\\\\1\\', \\'\\\\4\\');', $content);
变更为
$content = preg_replace_callback('#(\\s*)\\[cc([^\\s\\]_]*(?:_[^\\s\\]]*)?)([^\\]]*)\\](.*?)\\[/cc\\2\\](\\s*)#si', function($r){
return $this->PerformHighlightCodeBlock($r[4], $r[3], $content, $r[2], $r[1], $r[5]);
}, $content);
$content = preg_replace_callback('#(\\s*)\\<code(.*?)\\>(.*?)\\(\\s*)#si', function($r){
return $this->PerformHighlightCodeBlock($r[3], $r[2], $content, '', $r[1], $r[4]);
}, $content);
修改代码片段 2
$text = preg_replace('~*([0-9a-f]+);~ei', 'chr(hexdec("\\\\1"))', $text);
$text = preg_replace('~*([0-9]+);~e', 'chr(\\\\1)', $text);
变更为
$text = preg_replace_callback('~*([0-9a-f]+);~i', function($r){
return chr(hexdec($r[1]));
}, $text);
$text = preg_replace_callback('~*([0-9]+);~', function($r){
return chr($r[1]);
}, $text);
修改代码片段 3
$content = preg_replace('#(\\s*)(\\[cc[^\\s\\]_]*(?:_[^\\s\\]]*)?[^\\]]*\\].*?\\[/cc\\1\\])(\\s*)#sie', '$this->PerformProtectComment(\\'\\\\2\\', $content, \\'\\\\1\\', \\'\\\\3\\');', $content);
$content = preg_replace('#(\\s*)(\\<code.*?\\>.*?\\)(\\s*)#sie', '$this->PerformProtectComment(\\'\\\\2\\', $content, \\'\\\\1\\', \\'\\\\3\\');', $content);
变更为
$content = preg_replace_callback('#(\\s*)(\\[cc[^\\s\\]_]*(?:_[^\\s\\]]*)?[^\\]]*\\].*?\\[/cc\\1\\])(\\s*)#si', function($r){
return $this->PerformProtectComment($r[2], $content, $r[1], $r[3]);
}, $content);
$content = preg_replace_callback('#(\\s*)(\\<code.*?\\>.*?\\)(\\s*)#si', function($r){
return $this->PerformProtectComment($r[2], $content, $r[1], $r[3]);
}, $content);
修改代码片段 4
$text = preg_replace('/(< \\?php)/i', '<!--?php', $text);<br ?--> $text = preg_replace('/(?:^(?:\\s*[\\r\\n])+|\\s+$)/', '', $text);
变更为
$text = preg_replace_callback('/(< \\?php)/i', function($r){
return '<!--?php'; <br ?--> }, $text);
$text = preg_replace_callback('/(?:^(?:\\s*[\\r\\n])+|\\s+$)/', function($r){
return '';
}, $text);
相关文章
- MongoDB(4)- MongoDB与Python的交互
- MongoDB(3)- 数据的导入导出
- MongoDB(2)- MongoDB的基本操作
- MongoDB(1)- MongoDB数据库介绍与安装
- Linux(六):系统运维常用命令
- Linux(五):Linux的文档编辑器Vi
- Linux(四):Linux的打包和压缩详解
- Linux(三):Linux的目录及相关作用
- Linux(二):Linux的灵魂
- Linux(一):Linux操作系统
- Linux环境下安装配置Mysql
- (一)Git——安装与初始化
- (二)Git——基本操作
- (三)Git——分支
- (四)Git——团队协作
- Git——从入门到入云
- Linux嵌入式开发——shell命令
- Linux环境下接口调试利器:cURL
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- 【Golang】反射的三大laws