返回列表 回复 发帖

p::dump()方法

它是一个public方法,引用之后可以直接使,它有三个参数dump("弹出的内容","内容前的标记",bool),其中第二个参数跟第三个参数可选,第二个参数有值,页面在弹出的时候就会在弹出的变量前加上标识文字;第三个参数如果设置为true,它会把要弹出的内容赋给一个变量,不会显示在页面中(不知何意)。
; A" D9 ~; f- U" \$ n5 B$ [, z* k- f- k2 _; S
code:
1 S/ W( e1 z7 ]& [9 }+ U+ B2 I/ yfunction dump($vars, $label = '', $return = false); e# a- h3 L& x5 I8 y
{( i8 m1 M* q) U/ f- e8 s5 ~
    if (ini_get('html_errors')) {
# T6 ?: p4 r6 ~5 v8 c$ v        dump("ini_get('html_errors')");
3 b+ x; L) {1 k+ _        $content = '';
* J+ U9 S- C! d& g        if ($label != '') {dump('$label != ""');
% M1 e) l  p3 ~6 ]7 _            $content .= "<strong>{$label} :</strong><br/>\n--------<br/>\n";/ _5 ~% y' o) i7 G, p) V
        }
7 Q; P/ R  w' g+ A0 v        $content .= "<pre style=\"background-color: white;\">\n".htmlspecialchars(var_export($vars, true))."\n</pre>\n<hr/>";: _/ c& F+ h. \6 w2 Z( g
    } else {2 V0 h( W5 k- l, f- C0 z
        $content = $label . " :<br/>\n--------<br/>\n" . var_dump($vars, true)."\n<hr/>\n";
" R. ]" f3 E' N, e0 c8 i    }% E2 E8 R$ m1 ]' a- [
    if ($return) { return $content; }
; ~! X- {" |- u% E, u2 s& u    echo $content;
7 d0 r+ z0 Z4 }0 P# A    return null;
$ c  T; z5 g+ E* s}
下面是改良过的方法,每次使用都使这个
- q8 e: s  G1 f2 c4 U  S0 ifunction dump($vars, $label =true, $return = false)
+ W$ h' y! M# j7 \- T7 n{
$ @5 M! {3 w; r# k9 p/ o$ Q3 m. B    if (ini_get('html_errors')) {# i) h9 s" o1 N$ u  B! n% U8 R  p
        $content = '';
5 E* ^% T, p8 B: y% k0 H        if ($label == true) {
% \, s* l' U5 w% L% _/ W. ?            $content .= "<strong>".__FILE__ . '  ' . __LINE__ . "行:</strong>\n";
9 c* N. ]6 x: q. W! C        }0 R+ u' t' ?- c6 a; x: f" l- Z1 I
        $content .= "<pre style=\"background-color: white;\">".htmlspecialchars(var_export($vars, true))."</pre>";
- L* K3 J  v2 y8 q$ _6 ]    } else {
" i! Y8 E9 H, v1 W1 z) v  Q        $content = $label . " :<br/>\n--------<br/>\n" . var_dump($vars, true)."\n<hr/>\n";
, t6 |6 L5 l6 q    }
. `5 m: V7 y$ C1 U; Z    if ($return) { return $content; }' R0 L+ i# [3 R/ ^
    echo $content;# y$ ^- Y8 R; g# Z2 O  W  {. T% F
    return null;
+ P  @( W+ [, I% L}
function dump_plus($vars, $label =true, $return = false)) r) Z: v! ~5 j- A
{. G& e: J% E* O2 t
    if (ini_get('html_errors')) {6 g! m. \: J5 A1 _
        $content = '';1 K$ ~/ R, K/ t# `* K# W# L
        if ($label == true) {
3 Z2 w3 q9 x+ n  r) Y3 I! Q            $content .= "<strong style='color:red'>".__FILE__ . '  ' . __LINE__ . ":</strong>\n";
+ Z& H# W' M% W        }
3 n! w6 W0 x3 ]1 Q& l$ G/ Y7 K        $content .= "<pre style=\"background-color: white;\">".htmlspecialchars(var_export($vars, true))."</pre>";
8 v+ w% [" X: i    } else {9 |# @9 ]9 l6 K% u; P3 q- N6 X
        $content = $label . " :<br/>\n--------<br/>\n" . var_dump($vars, true)."\n<hr/>\n";
# ?- g+ ^  ~& q- V2 @' w    }
. l9 k* i7 t6 X. \    if ($return) { return $content; }2 K' l5 C8 D2 f- ^' q) w! [2 E
    echo $content;
) V' R4 A- j: u3 l; X8 e3 P    return null;3 T4 |1 u! \2 e! `' g3 |
}
返回列表