2
我的PHP代碼看起來像下面,則顯示空白我要顯示所有超鏈接的記錄,像simplexml_load_string的foreach犯規顯示任何
<a href="test.php?id=$Id">$Name</a>
,其中的$ id,$名稱是從XML飼料
$path = 'www.abc.com/test.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$returned = curl_exec($ch);
curl_close($ch);
// $xml === False on failure
$xml = simplexml_load_string($returned);
foreach($xml->Name as $Name){
print (string)$Name;
}
我的XML看起來像下面
<ABCXml version="1.1.0">
<Manufacturers>
<Item>
<Id>219</Id>
<Name>Matrix Corp</Name>
</Item>
<Item>
<Id>2040</Id>
<Name>Microcomputer</Name>
</Item>
</Manufacturers>
</ABCXml>
得到它的工作感謝:) – user580950