开发者

Output Buffer shows "1"

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 so开发者_如何学Pythonmehow 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜