Make var_dump look pretty

后端 未结 14 2468
忘掉有多难
忘掉有多难 2020-12-02 04:23

I have a simple $_GET[] query var set for showing testing data when pulling down queries from the DB.


  <         


        
14条回答
  •  -上瘾入骨i
    2020-12-02 04:34

    I wrote a function (debug_display) which can print, arrays, objects, and file info in pretty way.

    Idea Debug Method : 
            
    ';
        if(is_bool($var)) {
            echo $var === TRUE ? 'Boolean(TRUE)' : 'Boolean(FALSE)';
        }else {
            if(FALSE == empty($var) && $var !== NULL && $var != '0') {
                if(is_array($var)) {
                    echo "Number of Indexes: " . count($var) . "\n";
                    print_r($var);
                } elseif(is_object($var)) {
                    print_r($var);
                } elseif(@is_file($var)){
                    $stat = stat($var);
                    $perm = substr(sprintf('%o',$stat['mode']), -4);
                    $accesstime = gmdate('Y/m/d H:i:s', $stat['atime']);
                    $modification = gmdate('Y/m/d H:i:s', $stat['mtime']);
                    $change = gmdate('Y/m/d H:i:s', $stat['ctime']);
                    echo "
        file path : $var
        file size : {$stat['size']} Byte
        device number : {$stat['dev']}
        permission : {$perm}
        last access time was : {$accesstime}
        last modified time was : {$modification}
        last change time was : {$change}
        ";
                }elseif(is_string($var)) {
                    print_r(htmlentities(str_replace("\t", '  ', $var)));
                }  else {
                    print_r($var);
                }
            }else {
                echo 'Undefined';
            }
        }
        echo '
    '; $output = ob_get_contents(); ob_end_clean(); echo $output; unset($output); }

提交回复
热议问题