欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2024-02-17 11:19:52
...
我想用php读取xml的三个值
$url="http://www.cailele.com/static/ssc/newlyopenlist.xml";
$doc = new DOMDocument();
$doc->load($url); //读取xml文件
$lst = $doc->getElementsByTagName('row');
for ($i=0; $i $iframe= $lst->item($i);
$t1=$iframe->attributes->getNamedItem('expect')->value;
$t2=$iframe->attributes->getNamedItem('opencode')->value;
$t3=$iframe->attributes->getNamedItem('opentime')->value;
$t1=substr($t1,-9);
kjdata($t2,1,$t1,$t3);
}

我想读取xml的expec,opencode,opentime三个值,不知道为什么读取不上,求解答
------解决方案--------------------
$url = "http://www.cailele.com/static/ssc/newlyopenlist.xml";
$doc = new DOMDocument();
$doc->loadXML(curl_get($url));
$lst = $doc->getElementsByTagName('row');
for ($i=0; $i $iframe= $lst->item($i);
$t1=$iframe->attributes->getNamedItem('expect')->value;
$t2=$iframe->attributes->getNamedItem('opencode')->value;
$t3=$iframe->attributes->getNamedItem('opentime')->value;
$t1=substr($t1,-9);
kjdata($t2,1,$t1,$t3);
}

function kjdata() {
echo join(', ', func_get_args()), PHP_EOL;
}

function curl_get($durl) {
$cookiejar = realpath('cookie.txt');
$t = parse_url($durl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$durl);
curl_setopt($ch, CURLOPT_TIMEOUT,5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
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
小弟我想用php读取xml的三个值

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频