-1
다음 코드가 포함 된 test.php라는 PHP 파일이 있습니다.두 번 이상 호출 할 때 버퍼가 아무 것도 출력하지 않는 이유는 무엇입니까?
<?php
$text = 'Grrrrr';
ob_start();
require_once('testinc.php');
$html2 = ob_get_clean();
echo '<pre>';
var_dump($html2);
echo '</pre>';
$text = 'wtf';
ob_start();
require_once('testinc.php');
$html2 = ob_get_clean();
echo '<pre>';
var_dump($html2);
echo '</pre>';
testing('blah');
testing('123');
function testing($text) {
ob_start();
require_once('testinc.php');
$html = ob_get_clean();
echo '<pre>';
var_dump($html);
echo '</pre>';
}
testinc.php 파일에는 다음 코드가 포함되어 있습니다.
<?php
echo $text;
?>
testing
코드를 실행하면 출력이 다음과 같이 표시됩니다.
string(13) "Grrrrrtesting"
string(0) ""
string(0) ""
string(0) ""
이유는 버퍼는 처음보다 다른 작동하지 않습니다 어떻게 내가 출력은 다음과 같이받을 수 있나요?
string(13) "Grrrrrtesting"
string(10) "wtftesting"
string(11) "blahtesting"
string(10) "123testing"
ob_get_clean 및 require_ONCE에 대한 설명서를 읽으셨습니까? –
정말요?! require_once()를 include()로 변경하면 모든 것이 해결됩니다. – Casey
많은 출력 버퍼링을 사용하는 것은 일반적으로 코드를 잘못 구성한다는 것을 의미합니다. – nogad