Created
November 30, 2011 21:19
-
-
Save biozshock/1410884 to your computer and use it in GitHub Desktop.
Php nested ob_start explanation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// without OB | |
echo 'before_ob' . PHP_EOL; | |
ob_start(); // first level begins | |
// this line will be in $second | |
echo 'second_ob' . PHP_EOL; | |
ob_start(); // second level begins | |
// these 2 lines will be in $first | |
echo 'third_ob' . PHP_EOL; | |
echo '------' . PHP_EOL; | |
$first = ob_get_clean() . 1; | |
// this line will be in second | |
// but w/o previous 2 lines | |
echo '------' . PHP_EOL; | |
$second = ob_get_clean() . 2; | |
// this will output $first consisting of 2 lines. | |
// and $second without them. | |
var_dump($first, $second); | |
/** | |
Output: | |
before_ob | |
string(17) "third_ob | |
------ | |
1" | |
string(18) "second_ob | |
------ | |
2" | |
testscript: http://biozshock.com/test_ob.php | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment