note 97067 deleted from function.ob-get-contents by danbrown

From: Date: Wed, 31 Mar 2010 16:28:12 +0000
Subject: note 97067 deleted from function.ob-get-contents by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167585@lists.php.net to get a copy of this message
Note Submitter: me at unreal4u dot com ---- (set_environment.php) <?php // (...) ob_start(); include('includes/pages/'.$clean['get'].'.php'); $clean['page'] = ob_get_contents(); // (...) ?> (index.php) <?php include('includes/set_environment'); include('includes/header.php'); echo $clean['page']; include('includes/footer.php'); ?> With this code, PHP will output the buffers before printing out the headers. In order to output the buffer only when you need it, you MUST add ob_end_clean in order to clean the buffers before you output: (set_environment.php) <?php // (...) ob_start(); include('includes/pages/'.$clean['get'].'.php'); $clean['page'] = ob_get_contents(); ob_end_clean(); // (...) ?> It's all in the manual, but it took me some time to search the cause. Hopefully I can save you 5 minutes.

« previous php.notes (#167585) next »