|
-
Jul 23rd, 2004, 08:49 AM
#1
Thread Starter
Frenzied Member
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.
Last edited by ober0330; Jul 23rd, 2004 at 10:13 AM.
-
Jul 23rd, 2004, 09:03 AM
#2
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
-
Jul 23rd, 2004, 09:08 AM
#3
Thread Starter
Frenzied Member
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.
-
Jul 23rd, 2004, 10:14 AM
#4
Thread Starter
Frenzied Member
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.
-
Jul 23rd, 2004, 10:18 AM
#5
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.
-
Jul 23rd, 2004, 10:29 AM
#6
Thread Starter
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|