我刚刚升级到 PHP 7,并且一直在努力解决与不推荐使用的函数相关的错误,并取得了很大的成功。
可悲的是,我在为我的“在交互式可折叠 javascript 事物中查看 php 数组”代码修复新的 preg 替换方法时遇到了麻烦。
以下代码:
function print_r_tree($data)
{
// capture the output of $this->print_r_tree
$out = print_r($data, true);
// replace something like '[element] => <newline> (' with <a href="javascript:toggleDisplay('...');">...</a><div id="..." style="display: none;">
$out = preg_replace('/([ \t]*)(\[[^\]]+\][ \t]*\=\>[ \t]*[a-z0-9 \t_]+)\n[ \t]*\(/iUe',"'\\1<a href=\"javascript:toggleDisplay(\''.(\$id = substr(md5(rand().'\\0'), 0, 7)).'\');\">\\2</a><div id=\"'.\$id.'\" style=\"display: none;\">'", $out);
// replace ')' on its own on a new line (surrounded by whitespace is ok) with '</div>
$out = preg_replace('/^\s*\)\s*$/m', '</div>', $out);
// print the javascript function toggleDisplay() and then the transformed output
echo '<script language="Javascript">function toggleDisplay(id) { document.getElementById(id).style.display = (document.getElementById(id).style.display == "block") ? "none" : "block"; }</script>'."\n$out";
}
生成此警告。警告:preg_replace():不再支持 /e 修饰符,请改用 preg_replace_callback
删除第一个“preg_replace”中的“e”会破坏 javascript。我也尝试了一些 preg_replace_callback 的东西。
我一直在尝试使用此链接Replace preg_replace() e modifier with preg_replace_callback来帮助我了解损坏的内容,但我认为我的问题因 javascript 而变得复杂。
关于我的代码,我希望有人能够引导我完成这个过程?
提前致谢。