开发者

php and XML range into array

开发者 https://www.devze.com 2022-12-29 20:25 出处:网络
The code below helps be to get the WHOLE XML and put it into an array. What 开发者_如何转开发I\'m wondering is, what would be a good way to get the XML only from item 3 - 6 or any arbitrary range inst

The code below helps be to get the WHOLE XML and put it into an array. What 开发者_如何转开发I'm wondering is, what would be a good way to get the XML only from item 3 - 6 or any arbitrary range instead of the whole document.

 $d = new DOMDocument();
 $d->load('http://news.google.com/?output=rss');
 foreach ($d->getElementsByTagName('item') as $t) {
  $list = array ( 'title' => $t->getElementsByTagName('title')->item(0)->nodeValue);
  array_push($mt_arr, $list);
 }

Thanks


You can use Xpath.

You can either use DOMXpath or use the xpath method to create an Xpath query that will return the subset of nodes.

$d->xpath('/SOME/XPATH/STATEMENT');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号