2012-07-20 37 views
1

需要生成以下輸出的HTML代碼保存在txt文件的HTML輸出與PHP

<?php 
function video() { 
    $video = 'BYN-DEM7Mzw'; 
    echo '<script type="text/javascript"> 
    function youtubeFeedCallback(data){ 
     document.writeln(data.entry[ "media$group" ][ "media$description" ].$t.replace(/\n/g, "<br/>") + "<br/>"); } 
    </script> 
    <script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos/'.$video.'?v=2&amp;alt=json-in-script&amp;callback=youtubeFeedCallback"></script>'; 
} 
ob_start(); 
video(); 
$output = ob_get_clean(); 
$desc = $output; 
$video = 'BYN-DEM7Mzw'; 
$arq = $video.".txt"; 
$f = fopen($arq, "w+"); 
fclose; 
$f = fopen($arq, "a+"); 
$content = ""; 
if(filesize($arq) > 0) 
$content = fread($f, filesize($arq)); 
fwrite($f, $desc); 
fclose($f); 
?> 

問題該文件被保存了我的腳本,而不是輸出HTML

+0

你要保存的結果是YouTube會回來嗎? – DonSeba 2012-07-20 13:37:55

+0

我想保存從YouTube生成的輸出,如果視頻的描述 – 2012-07-20 13:51:18

+0

這樣他們就可以理解我的問題,我需要通過視頻的id從YouTube獲取視頻的描述並將此描述保存在自定義字段中使用相同的格式youtube – 2012-07-20 14:56:34

回答

0

我一個txt文件認爲你應該在其中使用正確的headers和正確的mime

例如

header('Content-Description: File Transfer'); 
header('Content-type: text/plain'); 
header('Content-Disposition: attachment; filename='.$file); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize($file)); 

if ($file != '') 
{ 
    echo file_get_contents($file); 
}