>백엔드 개발 >PHP 튜토리얼 >php读取网页文件的有关问题

php读取网页文件的有关问题

WBOY
WBOY원래의
2016-06-13 12:05:38981검색

php读取网页文件的问题
我想读取一个网页的一些数据,网址是:http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266

我的代码是这样的:

$url="http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266";<br /><br />		$doc = new DOMDocument();<br />		$doc->load($url); //读取xml文件<br />	//	$datas= $doc->saveXML();<br />//		$lst = $doc->getElementsByTagName('history1');<br />//		$t1 = $lst->item(0)->getElementsByTagName("draw")->item(0)->nodeValue; //取得name的标签的对象数组 <br />//		$t1 = substr($t1,2,6)."0".substr($t1,-2);<br />//		$t2 = $lst->item(0)->getElementsByTagName("prize_number")->item(0)->nodeValue; //取得name的标签的对象数组 <br />//		$t2 = str_replace("|",",",$t2);	<br />		<br />		<br />		$lst = $doc->getElementsByTagName('row');<br />	//    for ($i=0; $i<$lst->length; $i++) {<br />		for ($i=0; $i<2; $i++) {<br />			$iframe= $lst->item($i);<br />			$t1=$iframe->attributes->getNamedItem('draw')->value;<br />			$t2=$iframe->attributes->getNamedItem('prize_number')->value;


想获取第二行
<recent_draw><br /><draw>2014082856</draw><br /><prize_number>1|4|0|9|5</prize_number><br /><sale_count>57446</sale_count><br /><prize_levels>23</prize_levels>>

draw、prize_number请问应该怎么改
------解决方案--------------------
$url="http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266";<br />$doc = new DOMDocument();<br />$doc->load($url);<br /><br />$recent_draws=$doc->getElementsByTagName("recent_draw");<br /><br />$recent_draw=$recent_draws->item(0);<br />$draw=getNodeVal($recent_draw,"draw");<br />$prize_number=getNodeVal($recent_draw,"prize_number");<br /><br />echo $draw.'<br>';<br />echo $prize_number.'<br>';<br />function getNodeVal(&$myNode,$tagName){<br />	return $myNode->getElementsByTagName($tagName)->item(0)->nodeValue;<br />}<br />/*<br />2014082865<br />4<br><font color='#FF8000'>------解决方案--------------------</font><br>6<br><font color='#FF8000'>------解决方案--------------------</font><br>9<br><font color='#FF8000'>------解决方案--------------------</font><br>6<br><font color='#FF8000'>------解决方案--------------------</font><br>4<br />*/

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