【问题标题】:How to supress echoes from functions? [duplicate]如何抑制函数的回声? [复制]
【发布时间】:2013-01-23 14:48:20
【问题描述】:

可能重复:
PHP: Suppress output within a function?

我正在使用多个 php 脚本.."

包括我需要的库。问题是它们旨在以echoprintprint_r 的形式向浏览器提供输出

但是我需要使用它们并且不显示任何东西,我只关心它们所做的操作。有什么方法可以在不修改源代码的情况下抑制这些函数的输出?

【问题讨论】:

  • 你的意思是从客户端?
  • @BackinaFlash 不,服务器端。我正在调用函数

标签: php


【解决方案1】:

您可以使用output buffering,然后丢弃缓冲区:

ob_start();

function_that_prints_stuff_1();
function_that_prints_stuff_2();

// Done with the printing functions, discard the buffer:
ob_end_clean();

【讨论】:

    【解决方案2】:

    使用ob_startob_clean

    //start of your script
    ob_start();
    
    /*some library stuff*/
    
    // clean up the buffer
    ob_end_clean();
    
    /*your stuff*/
    

    【讨论】:

    • ob_end_clean not clean_end ;)
    猜你喜欢
    • 2010-11-09
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2013-06-17
    • 2014-10-17
    • 1970-01-01
    • 2020-01-23
    相关资源
    最近更新 更多