WP插件CodeColorer兼容PHP7
WP插件CodeColorer兼容PHP7
Last edited 2022-6-25
type
Post
status
Published
date
Mar 25, 2017
slug
codecolorer-php7
summary
本文参考官方文档 PHP7/preg_replace函数请定位codecolorer代码插件编辑界面并定位codecolorer/codecolorer-core.php文件修改4段代码
tags
建站
php
category
技术分享
icon
password
Property
Jun 25, 2022 10:28 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('/(&lt; \\?php)/i', '<!--?php', $text);&lt;br ?--> $text = preg_replace('/(?:^(?:\\s*[\\r\\n])+|\\s+$)/', '', $text);

变更为

$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);
 
  • 建站
  • php
  • Nginx反代理加速,打造自己的Gravatar头像缓存服务器Linux防火墙管理脚本,自动屏蔽网络威胁IP