页面类型
Post
发布状态
Published
发布日期
Mar 25, 2017
文章地址
codecolorer-php7
内容摘要
本文参考官方文档 PHP7/preg_replace函数请定位codecolorer代码插件编辑界面并定位codecolorer/codecolorer-core.php文件修改4段代码
文章标签
建站
php
文章分类
技术分享
icon代码
密码
Property
Dec 10, 2022 09:03 AM
本文参考官方文档 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);