• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

PHP源码方式打印

武飞扬头像
Luke
帮助3390

/**
 * [源码方式打印]
 * @E-mial wuliqiang_aa@163.com
 * @TIME   2017-04-07
 * @WEB    http://www.swvq.com
 * @param  [staing] $content [要打印的内容]
 * @param  [int] $status [类型]
 *  @param    [bool]  $path    [类型]
 *  @param    [array]  $pre_code_wlq_stop[类型]
 *
/
function pre($content = 'This is Empty Content', $status = 11, $path = false, $pre_code_wlq_stop = [0, 0]) : string
{
    $_SESSION['pre_code_wlq'] = empty($_SESSION['pre_code_wlq']) ? 1 : $_SESSION['pre_code_wlq']   1;
    $pre_code_wlq = (int) $_SESSION['pre_code_wlq'];

    echo "_____[{$pre_code_wlq}]【   Start Pre   】[{$pre_code_wlq}] _____ \r\n";

    $end_pre = "\r\n\r\n _____[{$pre_code_wlq}]【   End   Pre   】[{$pre_code_wlq}] _____\r\n";

    $backtrace = debug_backtrace();

    $path_array = ($status === false && is_array($path) && ($path[1] > 0 && $pre_code_wlq == $path[1]));

    if ($path === true || in_array($status, ['true', 'trues']) || (isset($pre_code_wlq_stop[1]) && $pre_code_wlq_stop[1] > 0 && $pre_code_wlq == $pre_code_wlq_stop[1]) || $path_array) {
        echo "\r\n [ Using the path ]     \r\n\r\n";
        $args = '';
        $type = ['object' => 'object', 'array' => 'array'];
        foreach ($backtrace as $k => $v) {
            foreach ($v['args'] as $ks => $vs) {
                if ($ks == (count($v['args']) - 1)) {
                    $args .= gettype($vs) . '  "' . (!empty($type[gettype($vs)]) ? gettype($vs) : (mb_strlen($vs) > 100 ? str_replace(["\r\n", "\n", "\r", "\t"], '\n', mb_substr($vs, 0, 100, 'UTF-8')) : $vs)) . '"';
                } else {
                    $args .= gettype($vs) . '  "' . (!empty($type[gettype($vs)]) ? gettype($vs) : (mb_strlen($vs) > 100 ? str_replace(["\r\n", "\n", "\r", "\t"], '\n', mb_substr($vs, 0, 100, 'UTF-8')) : $vs)) . '", ';
                }
            }
            echo "|    path ({$k}) :  [  " . $v['file'] . "  :  " . $v['line'] . "  ->  " . $v['function'] . " ( {$args} ) ]\n";
            $args = '';
        }

        echo "\r\n[ Run Memory ]    \r\n\r\n";

        $start_memory = isset($_SESSION['pre_start_memory']) ? $_SESSION['pre_start_memory'] : memory_get_usage();

        echo "|    PHP used memory :   [ " . number_format((memory_get_usage() - $start_memory) / 1024, 2) . " KB ]" . " -- [ " . number_format((memory_get_usage() - $start_memory) / 1024 / 1024, 2) . " MB ]" . "\r\n\r\n";

        echo "|    Total memory used : [ " . number_format(memory_get_usage() / 1024, 2) . " KB ]" . " -- [ " . number_format(memory_get_usage() / 1024 / 1024, 2) . " MB ]" . "\r\n\r\n";

        echo "|    System Allocates Maximum Memory : [ " . number_format(memory_get_peak_usage() / 1024, 2) . " KB ]" . " -- [ " . number_format(memory_get_peak_usage() / 1024 / 1024, 2) . " MB ]" . "\r\n";


        echo "\r\n[ Run Time ]    \r\n\r\n";

        $start_time = isset($_SESSION['pre_start_time']) ? $_SESSION['pre_start_time'] : microtime(true);

        echo "|    PHP used time : [ " . number_format(microtime(true) - $start_time, 8) . "秒 ]\r\n\r\n";

    }

    if ($content === true) {
        $status = 1;
    }

    if (in_array($status, ['true'])) {
        $status = 11;
    } else if (in_array($status, ['trues'])) {
        $status = 1;
    }

    if ($status === false && is_array($path) && ($path[0] > 0 && $pre_code_wlq == $path[0])) {
      $status = 11;
    }

    if ($pre_code_wlq_stop[0] > 0 && $pre_code_wlq == $pre_code_wlq_stop[0]) {
        $status = 11;
    }

    echo "\r\n[ Print Content ]    \r\n\r\n";

    switch ($status) {
        case 1:
            print_r($content);
            break;
        case 11:
            print_r($content);
            $_SESSION['pre_code_wlq'] = 0;
            exit($end_pre);
            break;
        case 2:
            var_dump($content);
            break;
        case 22:
            var_dump($content);
            $_SESSION['pre_code_wlq'] = 0;
            exit($end_pre);
            break;
    }

    echo $end_pre;

    return '';
}


这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/taneefh
系列文章
更多 icon
同类精品
更多 icon
继续加载