输出缓冲器显示“1” [英] Output Buffer shows "1"
问题描述
$ p $
core_function($ atts){
(attributes)
(核心函数,几个循环,回声,大量的直接输入)
}
这就是我如何使用输出缓冲显示我的函数(是的,我必须使用它!)。
pre $ display $ function $ atts {
(属性)
$输出= ob_start();
$ output。= core_function($ atts);
$ output。= ob_get_clean();
return $ output;
}
一切都很好,但是返回$ output不仅显示核心函数,还显示1在他们面前。我不知道这个1来自哪里。当我删除ob_start();和ob_get_clean();它消失了。所以我相信输出缓冲区以某种方式添加这个数字。但是,如何,为什么?这是一个原始的1,而不是段落等。
正常显示功能($ atts)显示,例如:
< div>这是核心功能!< / div>
并且通过输出缓冲显示:
1< div>这是核心功能!< / div>
为什么会发生这种情况?如果它与我的功能有关,我再说一遍 - 在所有内容之前,1正好显示出来。
这不是输出缓冲的工作方式。 ob_start
完成后返回TRUE或FALSE,这样您就连接了一堆不应连接的事物。 (您对core_function的调用也是如此)。
$ b $ pre $ display_function($ atts){
(attributes)
ob_start();
core_function($ atts);
return ob_get_clean();
}
应该有效。它打开输出缓冲,这将保存所有的输出(回声和打印等)。调用ob_get_clean将返回缓冲输出的内容。
I have two functions:
core_function($atts) {
(attributes)
(core functions, a few loops, echoes, a lot of direct input)
}
And that's how I display my function using output buffering (yes, I have to use it!).
display_function($atts) {
(attributes)
$output = ob_start();
$output .= core_function($atts);
$output .= ob_get_clean();
return $output;
}
Everything is perfectly fine, but return $output shows not only core functions but also "1" before them. I have no idea where this "1" comes from. When I deletete ob_start(); and ob_get_clean(); it disappears. So I believe the output buffer is somehow adding this digit. But how, and why? It's a raw "1", not in a paragraph etc.
Normaly display_function($atts) shows, for example:
<div>This is Core Function!</div>
And with output buffering it displays:
1 <div>This is Core Function!</div>
Why is it happening? If it has something to do with my functions I'm saying again - the 1 is being displayed exactly BEFORE all the contents.
That is not how output buffering works. ob_start
returns TRUE or FALSE upon completion so you are concatenating a bunch of things that shouldn't be concatenated. (The same goes for your call to core_function).
display_function($atts) {
(attributes)
ob_start();
core_function($atts);
return ob_get_clean();
}
Should work. It turns on output buffering which will save all of your output (echo's and prints etc). The call to ob_get_clean will return the contents of your buffered output.
这篇关于输出缓冲器显示“1”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!