ob_get_clean 和 ob_get_contents 将内容返回到屏幕,而不是与 var_dump 一起使用时将其放入变量中

发布于 2024-10-06 11:09:01 字数 566 浏览 0 评论 0原文

我使用这个函数进行调试:

function d($v,$tofile=null) {
    static $wasused;
    ob_start();
    var_dump($v);
    $dump = ob_get_clean();
    if (is_array($v)) $dump = preg_replace("@=>\n@",'=>',$dump);
    if (strlen($dump)>1000 or $tofile) {
        fileput('debug.txt',$dump,$wasused);
        echo n.n."strlen=".strlen($dump)."   >> debug.txt".n.n;
    }
    elseif (strlen($dump)<80) echo $dump;
    else echo n.n.$dump.n.n;
    $wasused=true;
}

问题是它有时会返回内容到控制台,特别是当这个内容是大数组上的 var_dump 结果时,

你们中有人以前见过这个问题吗?

I use this function for debugging:

function d($v,$tofile=null) {
    static $wasused;
    ob_start();
    var_dump($v);
    $dump = ob_get_clean();
    if (is_array($v)) $dump = preg_replace("@=>\n@",'=>',$dump);
    if (strlen($dump)>1000 or $tofile) {
        fileput('debug.txt',$dump,$wasused);
        echo n.n."strlen=".strlen($dump)."   >> debug.txt".n.n;
    }
    elseif (strlen($dump)<80) echo $dump;
    else echo n.n.$dump.n.n;
    $wasused=true;
}

the problem is it sometimes return content to console, particularly when this content is var_dump result on a big array,

anyone of you have seen this problem before ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百合的盛世恋 2024-10-13 11:09:01

如果这是在您的 php.ini 中:

implicit_flush = On

将其更改为:

implicit_flush = Off

If this is in your php.ini:

implicit_flush = On

change it to this:

implicit_flush = Off
陌路终见情 2024-10-13 11:09:01

在假设 var_dump 本身存在问题之前,需要验证 fileput() 是否完全按照问题所暗示的方式执行。

Before assuming that there is a problem with var_dump itself, one would need to verify that fileput() does exactly what the question implies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文