最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 解析XML DOMXPath的例子
时间:2022-11-14 23:00:16 编辑:袖梨 来源:一聚教程网
xml文件结构如下
php代码解析:
$url="";//输出xml的URL $dom = new DOMDocument('1.0', 'utf-8'); $dom->load($url);
这样我们捕获里XML数据,然后一点点截取,这段XML有多个URL节点,需要利DOMPATH解析
$xpath = new DOMXPath($dom); $node = '//url'; $length = $xpath->query($node)->length;
然后根据每个url内的字节点去获取数据
for($i = 0; $i < $length; $i++) { $data = array(); $m_date = date('Y-m-d', strtotime($xpath->query($node.'['.($i+1).']/date')->item(0)->nodeValue)); $m_start = $xpath->query($node.'['.($i+1).']/start')->item(0)->nodeValue; $m_end = $xpath->query($node.'['.($i+1).']/end')->item(0)->nodeValue; $m_title = $xpath->query($node.'['.($i+1).']/title')->item(0)->nodeValue; $m_format = $xpath->query($node.'['.($i+1).']/format')->item(0)->nodeValue; $m_season = $xpath->query($node.'['.($i+1).']/season')->item(0)->nodeValue; $m_round = $xpath->query($node.'['.($i+1).']/round')->item(0)->nodeValue; /*$homeTeam = $xpath->query($node.'['.($i+1).']/homeTeam')->item(0)->nodeValue; if(empty($homeTeam)) continue; $guestTeam = $xpath->query($node.'['.($i+1).']/guestTeam')->item(0)->nodeValue; if(empty($guestTeam)) continue;*/ $homeTeam = $xpath->query($node.'['.($i+1).']/homeTeam')->item(0)->nodeValue; $guestTeam = $xpath->query($node.'['.($i+1).']/guestTeam')->item(0)->nodeValue; if(empty($guestTeam) || empty($homeTeam)) { if($m_title){ $temp_title=explode(" ", $m_title); list($homeTeam,$guestTeam)=explode("vs", $temp_title[1]); unset($temp_title); } } if(empty($homeTeam)) continue; if(empty($guestTeam)) continue; }
相关文章
- 《原神》5.2卡池抽取建议 11-14
- 《原神》5.2版本新怪物介绍 11-14
- 《原神》希诺宁增伤触发方法 11-14
- 《原神》循音觅奇活动入口 11-14
- 《原神》循音觅奇兑换码获取方法 11-14
- 《原神》花羽会活动飞行技巧介绍 11-14