2009-04-15 34 views

回答

2

最簡單的方法是用file_get_contents()

$xmlString = file_get_contents('http://www...../file.xml'); 

如果你想SimpleXML對象,你可以使用simplexml_load_file()

$xml = simplexml_load_file('http://www...../file.xml'); 

這兩種方法都需要allow_url_fopen啓用。如果不是,你可以使用curl - 這更復雜,但也給你更多的靈活性。

$c = curl_init('http://www...../file.xml'); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 

$xmlString = curl_exec($c); 
$error = curl_error($c); 
curl_close($c); 

if ($error) 
    die('Error: ' . $error);