-
ob_start [resolved]
Does ob_start not work for something where you echo statements? I have some code where I put ob_start at the top, it fills a select box, and then I want to insert it later, not immediately, so can't I do a flush of the buffer to spit it out later?
I hope that makes sense.
-
No, that's not quite how it works.... at least that's not how I understand it works. when you use ob_start, I think it jsut simply ques things up, just doesn't send it to the client right away. when you then flush it, it still sends everything in the same order it was queued up in.... I think... don't hold me to it, I could be wrong.
TG
-
Well... that's not exactly what I'm asking. It doesn't seem to be holding the output in the buffer. Every echo statement after ob_start goes straight to the output. It doesn't wait for me to say ob_end_flush.
-
Ok, I think I misunderstood the purpose of this function, so I've made my own function to suit my needs and I just call that function when I need the output now.
-
Try this PHP script:
PHP Code:
<?php
ob_start ();
/* echo statements go here */
echo ("1) this will be printed\n");
ob_start ();
/* more echo statements go here */
echo ("2) this won't be printed\n");
ob_end_clean (); /* discards contents */
ob_start ();
echo ("3) this will be printed\n");
ob_end_flush (); /* will flush this buffer into the top buffer */
/* echo statments */
echo ("4) this will be printed\n");
/* send a header */
header ('Content-Type: text/plain');
ob_end_flush ();
?>
That is a short demonstartion of how the output buffering works. You should get the following output:
Code:
1) this will be printed
3) this will be printed
4) this will be printed
If you don't get that then there is a problem with output buffering. You should check the directive implicit_flush is set 0 in your php.ini.
-
Well... my problem was that I wasn't putting that at the top of the page, because I need to analyze some input before I get to that point... and I guess I don't really want to do all that before sending the headers.