PHP常用的输入变量函数print_r,但是输出没有换行,看起来很费力
我们可以自定义一个函数来实现变量的格式化输出,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function dump( $vars , $label = '' , $return = false) { if ( ini_get ( 'html_errors' )) { $content = "<pre>\n" ; if ( $label != '' ) { $content .= "<strong>{$label} :</strong>\n" ; } $content .= htmlspecialchars(print_r( $vars , true)); $content .= "\n</pre>\n" ; } else { $content = $label . " :\n" . print_r( $vars , true); } if ( $return ) { return $content ; } echo $content ; return null; } |
原创文章,转载请注明:转载自Web开发笔记 | PHP格式化输出打印变量
本文链接地址:https://www.magentonotes.com/php-print-format-function.html
Comments on this entry are closed.