php – 理解print_r输出
发布时间:2020-12-13 17:39:30 所属栏目:PHP教程 来源:网络整理
导读:有些情况下,print_r的输出非常复杂,冗长且难以阅读,例如对象,嵌套数组,嵌套对象,… 是否有图书馆或工具来帮助开发人员阅读这些信息?像DOM的DOM检查器? 解决方法 在筛选print_r输出时,我经常使用此功能.这是一个很棒的快速选择. http://www.php.net/manual/
有些情况下,print_r的输出非常复杂,冗长且难以阅读,例如对象,嵌套数组,嵌套对象,…
是否有图书馆或工具来帮助开发人员阅读这些信息?像DOM的DOM检查器? 解决方法
在筛选print_r输出时,我经常使用此功能.这是一个很棒的快速选择.
http://www.php.net/manual/en/function.print-r.php#90759归功于鲍勃 <?php function print_r_tree($data) { // capture the output of print_r $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().' '),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"; } ?> 如果您使用Drupal作为标记暗示,您可以将它放在主题的template.php文件中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |