Flying Sagittarius Posted June 13, 2008 Share Posted June 13, 2008 How do you use output buffering? Link to comment https://forums.phpfreaks.com/topic/110012-output-buffering/ Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 from php: <?php function callback($buffer) { // replace all the apples with oranges return (str_replace("apples", "oranges", $buffer)); } ob_start("callback"); ?> <html> <body> <p>It's like comparing apples to oranges.</p> </body> </html> <?php ob_end_flush(); ?> The above example will output: <html> <body> <p>It's like comparing oranges to oranges.</p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/110012-output-buffering/#findComment-564530 Share on other sites More sharing options...
Flying Sagittarius Posted June 13, 2008 Author Share Posted June 13, 2008 How does it work? What does it do? Is there a resource I can use? Link to comment https://forums.phpfreaks.com/topic/110012-output-buffering/#findComment-564531 Share on other sites More sharing options...
bluejay002 Posted June 13, 2008 Share Posted June 13, 2008 check this out: http://www.phpfreaks.com/forums/index.php/topic,197357.0.html you may also use the search right above.... you will get a lot of results there. Link to comment https://forums.phpfreaks.com/topic/110012-output-buffering/#findComment-564538 Share on other sites More sharing options...
Rayhan Muktader Posted June 13, 2008 Share Posted June 13, 2008 "how does it work?" When you use output buffering, the result generated by php(usually html) is sent to a buffer (meaning saved in memory) instead of directly being sent to the browser. The saved material will wait in the buffer until you tell it go to the browser. The primary use for output buffering is header redirection. As you may know that a header resides at the very beginning of a html file and a html file can have only one header. Therefore, you can't do a header redirection in the middle of a page. But you can do this if you are using output buffering. Because the page goes to the buffer and does not get displayed by the browser(using the first header) first. The bad news is that output buffering taxes the server. And crappy servers will generate memory errors every now and then. Hope that makes thing clearer for you. Link to comment https://forums.phpfreaks.com/topic/110012-output-buffering/#findComment-564553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.