【求助】preg_replace转成preg_replace_callback

hua_zhixing_ 2014-07-31 12:44:16
如何把下面代码中的preg_replace用preg_replace_callback代替?
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";


这是ECShop里的代码,安装在php 5.5.x版本上时,会出现这类问题。
...全文
143 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hua_zhixing_ 2014-07-31
  • 打赏
  • 举报
回复
转成:
$out = "<?php \n" . '$k = ' . preg_replace("/(\\'\$[^,]+)/" , function($r){return stripslashes(trim($r[1],'\''));}, var_export($t, true)) . ";\n";
报错:
Catchable fatal error: Object of class Closure could not be converted to string in /webapp/www/ecshop/includes/cls_template.php on line 494
xuzuning 2014-07-31
  • 打赏
  • 举报
回复
preg_replace_callback("/(\\'\$[^,]+)/" , function($r){return stripslashes(trim($r[1],'\''));}, var_export($t, true))

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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