load($url); //读取xml文件 $lst = $doc-&"/> load($url); //读取xml文件 $lst = $doc-&">

 >  기사  >  백엔드 개발  >  小弟我想用php读取xml的三个值

小弟我想用php读取xml的三个值

WBOY
WBOY원래의
2016-06-13 11:55:24718검색

我想用php读取xml的三个值

$url="http://www.cailele.com/static/ssc/newlyopenlist.xml";<br />		$doc = new DOMDocument();<br />		$doc->load($url); //读取xml文件<br />		$lst = $doc->getElementsByTagName('row');<br />		for ($i=0; $i<2; $i++) {<br />			$iframe= $lst->item($i);<br />			$t1=$iframe->attributes->getNamedItem('expect')->value;<br />			$t2=$iframe->attributes->getNamedItem('opencode')->value;<br />			$t3=$iframe->attributes->getNamedItem('opentime')->value;<br />			$t1=substr($t1,-9);<br />			kjdata($t2,1,$t1,$t3);<br />		 } <br />		 

我想读取xml的expec,opencode,opentime三个值,不知道为什么读取不上,求解答
------解决方案--------------------
$url = "http://www.cailele.com/static/ssc/newlyopenlist.xml";<br />$doc = new DOMDocument();<br />$doc->loadXML(curl_get($url));<br />$lst = $doc->getElementsByTagName('row');<br />for ($i=0; $i<2; $i++) {<br />  $iframe= $lst->item($i);<br />  $t1=$iframe->attributes->getNamedItem('expect')->value;<br />  $t2=$iframe->attributes->getNamedItem('opencode')->value;<br />  $t3=$iframe->attributes->getNamedItem('opentime')->value;<br />  $t1=substr($t1,-9);<br />  kjdata($t2,1,$t1,$t3);<br />}<br /><br />function kjdata() {<br />  echo join(', ', func_get_args()), PHP_EOL;<br />}<br /><br />function curl_get($durl) {<br />  $cookiejar = realpath('cookie.txt');<br />  $t = parse_url($durl);<br />  $ch = curl_init();<br />  curl_setopt($ch, CURLOPT_URL,$durl);<br />  curl_setopt($ch, CURLOPT_TIMEOUT,5);<br />  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);<br />  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);<br />  curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");<br />  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);<br />  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);<br />  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);<br />  $r = curl_exec($ch);<br />  curl_close($ch);<br />  return $r;<br />}<br />
5,9,6,4,2, 1, 140421023, 2014-04-21 01:55:30
7,6,4,2,4, 1, 140421022, 2014-04-21 01:50:30

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.