2014-09-09 2 views
-1

보다는 content.php에서 PHP 코드를 브라우저에 출력 될 :PHP 파일을 포함하고 출력을 파일에 씁니다.

<?php 

include 'content.php'; 

실행 된 결과를 로컬 텍스트 파일에 기록하는 것 외에 브라우저로 출력하지 얻는 방법 :

<?php 

include 'content.php'; 
// not output to browser 
// but grab the results and write them to content.txt 

어떻게해야합니까?

+0

파일을 변수로 반환하고 해당 변수를 파일에 씁니다. –

+0

나는 당신이'ob_get_contents'를 원한다고 생각합니다. – Onimusha

답변

2

데이터를 캡처하려면 output buffering을 사용하고 캡처 한 출력을 저장하려면 file_put_contents()을 사용하십시오.

ob_start(); 
include 'content.php'; 
$content = ob_get_clean(); 
file_put_contents('file.txt', $content); 
0

당신은 파일을 다운로드 헤더를 설정하고 file_get_contents을 사용하여 파일의 내용을 에코 할 수 있습니다.

header('Content-type: text/plain'); 
header('Content-Disposition: attachment; filename="content.php"'); 
$html = file_get_contents('content.php'); 
echo $html; 
관련 문제