2011-06-12 50 views

回答

2

你的問題很混亂,但我想你想在變量中的文件內容? 對於您可以使用file_get_contents

$var = file_get_contents('http://php.net/manual/en/function.file-get-contents.php'); 
2

可以使用file_get_contents()這樣:

$var = file_get_contents('http://www.xyz.com/give_data.php?id=4'); 

但是,這只是返回無論give_data.php腳本輸出爲字符串。如果您需要更高級的數據類型,我會建議在獲取數據以獲取原始數據後,在give_data.php和$var = json_decode($var);中使用json_encode()。請注意,這不適用於複雜的PHP對象。如果你真的需要,你可以使用serialize()和unserialize(),但它不是標準的,只能用於PHP。

+1

如果失敗,你可能已經在ini了allow_url_fopen關掉,還是有一定的safe_mode設置阻止你。在這種情況下,如果你不能改變這些設置,那麼看看使用cURL來繞過它,只是說'。 – Cups 2011-06-12 22:15:05

+0

好點,但如果你有這些限制,你可能想尋找另一個主機:) – Seldaek 2011-06-12 22:20:25

+0

在外部來源使用file_get_contents()只是讓我畏懼。 – Cups 2011-06-12 22:25:02

相關問題