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

php读取网页文件的问题

程序员文章站 2022-05-12 11:11:17
...
我想读取一个网页的一些数据,网址是:http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266

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


想获取第二行
20140828561|4|0|9|55744623>

draw、prize_number请问应该怎么改


回复讨论(解决方案)

$url="http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266";$doc = new DOMDocument();$doc->load($url);$recent_draws=$doc->getElementsByTagName("recent_draw");$recent_draw=$recent_draws->item(0);$draw=getNodeVal($recent_draw,"draw");$prize_number=getNodeVal($recent_draw,"prize_number");echo $draw.'
';echo $prize_number.'
';function getNodeVal(&$myNode,$tagName){ return $myNode->getElementsByTagName($tagName)->item(0)->nodeValue;}/*20140828654|6|9|6|4*/