2013-11-26 65 views
-1

代碼片段中描述的PHP行爲的原因是什麼?PHP行爲:爲什麼PHP標籤中的代碼不顯示在屏幕上?

// "demo.txt" is a plain text file. 
// Content is read into a string. 
$demo = file_get_contents('http://example.com/demo.txt'); 
// Browser displays the content of the text-file. 
echo $demo; 

// "functions.php" is a php-file. 
// Read into a string. 
$demo = file_get_contents('http://example.com/functions.php'); 
// Browser displays nothing. 
echo $demo; 
+0

什麼行爲? – Damodaran

+0

當提出問題時,請提供一個具體示例,說明您正在嘗試實現的目標以及您目前所做的工作。要詳細瞭解如何提出重要問題,請參閱如何提問 - http://stackoverflow.com/questions/如何提問 – Damodaran

+2

當您通過HTTP請求PHP文件時,它通常由服務器進行分析,因此您將獲得的唯一輸出是PHP腳本生成的輸出(如果有的話)。如果它不產生任何輸出,你將不會相應地輸出。 (想想看,如果情況並非如此,那麼任何人都可以讀取數據庫密碼等,您可能已經將它們存儲在PHP文件中的變量中。) – CBroe

回答

0
$demo = file_get_contents('http://example.com/functions.php'); 
echo $demo; 

$demo包含任何鏈接的回報。 「http://example.com/functions.php」是一個php文件,它沒有給出任何輸出,這意味着它在執行期間不輸出任何內容。所以你沒有得到明顯的結果。

如需更多瞭解,請將echo "Hello world";放入您的function.ph p文件中,然後執行。您將獲得「Hello world」作爲內容。

+0

您已經幫助我瞭解了這個問題。謝謝。 –

相關問題