2012-04-28 64 views
1

我已經在停止運行之前和之後放置了一個echo。文件file1.txt被寫入,但是最後的echo確認沒有被返回。來自教程的PHP示例不會一直運行通過

<?php 
$fh = fopen("file1.txt", 'w') or die("Failed to create file"); 
$text = <<<_END 
Line 1 
Line 2 
Line 3 

_END; 
fwrite($fh, $text) or die("Could not write to file"); 

echo "This shows up in my browser"; 
$fclose($fh); 
echo "This doesn't"; 
?> 

回答

5

你的腳本有錯誤

更換

$fclose($fh); 

隨着

fclose($fh); 

要查看所有錯誤添加到您的網頁

error_reporting(E_ALL); 
ini_set('display_errors','On'); 

頂部既然你正在學習如果你要玩的變量函數這會工作

$fclose = "fclose"; 
$fclose ($fh); 

最後你的代碼的簡化版本使用file_put_contentshttp://php.net/manual/en/function.file-put-contents.php

$text = <<<_END 
Line 1 
Line 2 
Line 3 
_END; 
file_put_contents ("file1.txt", $text); 
echo "This shows up in my browser"; 
+0

涼爽,有助於學習的目的。謝謝! – iDontKnowBetter 2012-04-28 22:37:30

+0

歡迎您....不斷學習...... – Baba 2012-04-28 22:38:02

2

$fclose($fh);應該是fclose($fh);。這是一個功能,而不是可變的。