ecshop2.7.3 preg_replace()如何替换成preg_replace_callback()?

shi214785 2013-07-23 12:54:09
我的ecshop进入index页后就一直报Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in D:\ecshop\apache2.4.4\htdocs\ec\includes\cls_template.php on line 300 的错误,请问我应该怎么改?

php 5.5
apache 2.4.4
ecshop 2.7.3
...全文
52082 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
winiscsi 2016-03-15
  • 打赏
  • 举报
回复
$str = preg_replace("/<\?php([^\?]+)\?>/es", "template_addquote('<?php\\1?>')", $str); $str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\+\-\x7f-\xff]+)\}/es", "template_addquote('<?php echo \\1;?>')", $str); 这 2 个 如何替换 这里的 /es 是什么意思 报错
lanxin_12300 2016-01-25
  • 打赏
  • 举报
回复
谢谢真好 学到好多东西
sinat_28215067 2015-11-04
  • 打赏
  • 举报
回复
$_GET[C('VAR_CONTROL')] = ucwords(preg_replace('@_([a-z]?)@ei', 'strtoupper("\1")', $_GET[C('VAR_CONTROL')])); 这个该如何换呢?求帮助
sinat_28215067 2015-11-04
  • 打赏
  • 举报
回复
//模块名称改为pascal命名 $_GET[C('VAR_CONTROL')] = ucwords(preg_replace('@_([a-z]?)@ei', 'strtoupper("\1")', $_GET[C('VAR_CONTROL')])); Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in C:\wamp\www\hdphp\Lib\Core\Route.class.php on line 114 求帮助、该如何换
我叫江城 2015-09-27
  • 打赏
  • 举报
回复
帮帮忙,看看这个怎么转
return preg_replace(array(
                                 '/(^|_|-)+(.)/e', '/\.(.)/e'
                            ), array(
                                    "strtoupper('\\2')", "'_'.strtoupper('\\1')"
                               ), $id);
  • 打赏
  • 举报
回复
那这个$modFilePath = preg_replace('/([^*]+)/e', 'preg_quote("$1", "~")', $modFilePath);怎么装换成preg_replace_callback()
syt109 2014-10-29
  • 打赏
  • 举报
回复
非常感谢,学习了。顶
fffy2366 2014-07-25
  • 打赏
  • 举报
回复
引用 7 楼 wihon 的回复:
顶版主。求帮助: $pattern = array( '/<!--[^>|\n]*?({.+?})[^<|{|\n]*?-->/', // 替换smarty注释 '/<!--[^<|>|{|\n]*?-->/', // 替换不换行的html注释 '/(href=["|\'])\.\.\/(.*?)(["|\'])/i', // 替换相对链接 '/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir '/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir '/{nocache}(.+?){\/nocache}/ise', //无缓存模块 ); $replace = array( '\1', '', '\1\2\3', '\1' . $tmp_dir . '\2', '\1' . $tmp_dir . '\2', "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'", ); return preg_replace($pattern, $replace, $source); 这个里面的"preg_replace"换成"preg_replace_callback",怎么写?谢谢大大。
这样可以:


        $pattern = array(
            '/<!--[^>|\n]*?({.+?})[^<|{|\n]*?-->/', // 替换smarty注释
            '/<!--[^<|>|{|\n]*?-->/',               // 替换不换行的html注释
            '/(href=["|\'])\.\.\/(.*?)(["|\'])/i',  // 替换相对链接
            '/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir
            '/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir
            //'/{nocache}(.+?){\/nocache}/ise', //无缓存模块
            '/{nocache}(.+?){\/nocache}/', //无缓存模块
            );
        $replace = array(
            '\1',
            '',
            '\1\2\3',
            '\1' . $tmp_dir . '\2',
            '\1' . $tmp_dir . '\2',
            "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'",
            );
        $source = preg_replace_callback($pattern[0], function($match){return $match[1];}, $source);
        $source = preg_replace_callback($pattern[1], function($match){return '';}, $source);
        $source = preg_replace_callback($pattern[2], function($match){return $match[1].$match[2].$match[3];}, $source);
        $source = preg_replace_callback($pattern[3], function($match){return $match[1]. $tmp_dir .$match[2];}, $source);
        $source = preg_replace_callback($pattern[4], function($match){return $match[1]. $tmp_dir .$match[2];}, $source);
        $source = preg_replace_callback($pattern[5], function($match){return "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode($match[1]) . '}'";}, $source);
        return $source ;

syuanx123 2014-05-27
  • 打赏
  • 举报
回复
Warning: preg_replace_callback(): Requires argument 2, 'function(){return '{include file='.strtolower(). '}';}', to be a valid callback in D:\myweb\www\ecshop\includes\cls_template.php on line 1072 $pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se'; $replacement = "'{include file='.strtolower('\\1'). '}'"; $source = preg_replace($pattern, $replacement, $source); 请问版主这里应该如何改?
wihon 2014-03-19
  • 打赏
  • 举报
回复
顶版主。求帮助: $pattern = array( '/<!--[^>|\n]*?({.+?})[^<|{|\n]*?-->/', // 替换smarty注释 '/<!--[^<|>|{|\n]*?-->/', // 替换不换行的html注释 '/(href=["|\'])\.\.\/(.*?)(["|\'])/i', // 替换相对链接 '/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir '/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir '/{nocache}(.+?){\/nocache}/ise', //无缓存模块 ); $replace = array( '\1', '', '\1\2\3', '\1' . $tmp_dir . '\2', '\1' . $tmp_dir . '\2', "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'", ); return preg_replace($pattern, $replace, $source); 这个里面的"preg_replace"换成"preg_replace_callback",怎么写?谢谢大大。
jiawt117 2014-02-19
  • 打赏
  • 举报
回复
引用 5 楼 xuzuning 的回复:
自定义函数的形参不是由你自己命名的吗? 你只需满足 preg_replace_callback 的回调函数需要接受一个数组就行了
麻烦问一下这句怎么改 $out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
xuzuning 2013-08-11
  • 打赏
  • 举报
回复
自定义函数的形参不是由你自己命名的吗? 你只需满足 preg_replace_callback 的回调函数需要接受一个数组就行了
lujunjie521 2013-08-10
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
那就是
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);
如果还有其他的地方报这样的错,就参照这个改
请问function($r) 中的参数$r 你是依据什么定义的啊,我换成别的字母就不行了哦,麻烦讲讲其中的道理啊
xuzuning 2013-07-23
  • 打赏
  • 举报
回复
那就是
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);
如果还有其他的地方报这样的错,就参照这个改
shi214785 2013-07-23
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
preg_replace_callback($pattern, function($r) { return 与$r相关的值; }, $subject) 你应该给出 cls_template.php 第 300 行的代码 这样才能给你准确的写法
代码是这样的:return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
xuzuning 2013-07-23
  • 打赏
  • 举报
回复
preg_replace_callback($pattern, function($r) { return 与$r相关的值; }, $subject) 你应该给出 cls_template.php 第 300 行的代码 这样才能给你准确的写法

24,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧