我正在嘗試從網站獲取xml文件並將其放入本地空xml文件(myxml.xml
)中。我的代碼是返回一個空文件。PHP將文件內容從url寫入本地文件
我們的目標是從http://website.com/theirxml.xml
中獲取xml文件內容並將其放入myxml.xml
。
要注意,我這樣做的唯一原因是因爲我的主機網站上的xml格式不正確,所以我需要在我自己的本地版本上更改它。因此,我需要的是從文件中獲取字符串。
<?php
$myfile = fopen("myxml.xml", "w") or die("Unable to open file!");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://website.com/theirxml.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
fwrite($myfile, $output);
fclose($myfile);
?>
而你的問題是? –
我沒有得到任何迴應,也沒有錯誤陳述。 –
無論你的方式或@ colbuton的方式(我更喜歡)使用'error_reporting(E_ALL); ini_set('display_errors','1');' – AbraCadaver