load($url); //读取xml文件 $lst = $doc-&"/> load($url); //读取xml文件 $lst = $doc-&">
Home > Backend Development > PHP Tutorial > 小弟我想用php读取xml的三个值

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:55:24
Original
752 people have browsed it

我想用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 />		 
Copy after login

我想读取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 />
Copy after login
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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template