【发布时间】:2013-07-23 14:59:15
【问题描述】:
使用这个简单的脚本:
ob_start();
$text = array();
echo 'first text';
$text[] = ob_get_clean();
echo 'second text';
$text[] = ob_get_clean();
echo 'third text';
$text[] = ob_get_clean();
echo 'fourth text';
$text[] = ob_get_clean();
print_r($text);
这个输出:
third textfourth textArray
(
[0] => first text
[1] => second text
[2] =>
[3] =>
)
但我希望:
Array
(
[0] => first text
[1] => second text
[2] => third text
[3] => fourth text
)
【问题讨论】:
-
当我尝试它时,我只得到数组中的第一个文本。似乎 ob_get_clean 的结果非常不一致
-
@StephenTG 我明白你的意思。 PHPFiddle 工作两次:phpfiddle.org/lite/code/u4z-us5 但phpcodepad.com 只工作一次
标签: php output-buffering ob-start