2009-04-15 41 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);