本文参考官方文档 PHP7/preg_replace函数
请定位codecolorer代码插件编辑界面并定位codecolorer/codecolorer-core.php文件修改4段代码


修改代码片段 1

1
2
$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);

变更为

1
2
3
4
5
6
$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

1
2
$text = preg_replace('~*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text);
$text = preg_replace('~*([0-9]+);~e', 'chr(\\1)', $text);

变更为

1
2
3
4
5
6
$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

1
2
$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);

变更为

1
2
3
4
5
6
$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

1
$text = preg_replace('/(&lt; \?php)/i', '<!--?php', $text);&lt;br ?--> $text = preg_replace('/(?:^(?:\s*[\r\n])+|\s+$)/', '', $text);

变更为

1
2
3
4
5
$text = preg_replace_callback('/(&lt; \?php)/i', function($r){
return '<!--?php'; &lt;br ?--> }, $text);
$text = preg_replace_callback('/(?:^(?:\s*[\r\n])+|\s+$)/', function($r){
return '';
}, $text);
文章协议: Attribution-NonCommercial-NoDerivatives
文章地址: https://www.hscbook.com/article/codecolorer-php7/
除非注明,本博文章均为原创,转载请以链接形式标明本文地址