ob_start echo的字符串仍然没有显示 [英] ob_start echo's strings out still
本文介绍了ob_start echo的字符串仍然没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果ob_start()不允许echo的输出返回其正常目的地,而只是记录其内容,我会很喜欢.但是它似乎没有这样做.有任何想法吗?这是我的代码:
I'd like it if ob_start() didn't let echo's output to their normal destination and just log their contents instead. But it doesn't seem to be doing that. Any ideas? Here's my code:
<?php
ob_start();
echo 'test';
$out = ob_get_contents();
var_dump($out);
测试仍在回显.它也是var_dump'd,但是我不希望它被回显.
test is still echo'd. It's var_dump'd, as well, but I don't want it to be echo'd.
有什么想法吗?
谢谢!
推荐答案
输出缓冲区在脚本末尾自动刷新,因此是预期的行为.
The output buffer is automatically flushed at the end of the script, so it's expected behaviour.
您正在寻找 ob_get_clean()
,它会在清除之前返回当前缓冲区:
You are looking for ob_get_clean()
, which returns the current buffer before clearing it:
$out = ob_get_clean();
这篇关于ob_start echo的字符串仍然没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文