dqu94359 2011-06-21 02:11
浏览 27
已采纳

PHP:我可以抑制函数的输出吗?

So I know you can use output buffer. The problem right now is, I am using a function in a Wordpress plugin and it is automatically and it automatically outputs the return. However, I want to check the return to see if it is false or returning my data.

I have tried:

if( function_name() ) {

}

$name = function_name();

I can still see the output in those situations, which I why I wanted to suppress it and do some checks first. I don't want to edit the core function of the plugin, but I will as a last resort. Is there a better work around?

  • 写回答

2条回答 默认 最新

  • douwo3665 2011-06-21 02:13
    关注

    Yes. It can be done like this:

    ob_start();
    if (function_name()) { }
    else {}
    
    // then you can do one of the following
    ob_end_clean(); // in case you want to suppress function_name output
    ob_flush(); // in case you don't want to suppress function_name output
    

    Have a look here for more information about output control functions.

    Also, instead of using ob_flush and ob_end_clean you could use ob_get_clean.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C