我在服务器上调用PHP cURL方法,响应为XML类型。cURL将输出(在删除标记之后)保存在标量类型变量中。有没有一种方法可以将其存储在对象/哈希/数组中,以便于解析?
<?php function download_page($path){ $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); $retValue = curl_exec($ch); curl_close($ch); return $retValue; } $sXML = download_page('http://alanstorm.com/atom'); $oXML = new SimpleXMLElement($sXML); foreach($oXML->entry as $oEntry){ echo $oEntry->title . "\n"; }