开发者

How to parse XML using PHP no code?

I am learning how to parse in various languages. Right now I am trying to learn PHP. Can anyone help get me started?

h开发者_运维百科ttp://www.nfl.com/liveupdate/scorestrip/ss.xml

is the page I would like to parse using PHP. Is this possible and how do you do it with PHP?


Try this:

<?php
  $xml=simplexml_load_file('http://www.nfl.com/liveupdate/scorestrip/ss.xml');
  print_r($xml);
?>

http://www.php.net/manual/en/book.simplexml.php


Simple XML is good if you need a DOM interface to the XML, but if you need something quick just to go from XML into an associative array there's a great utility script that's super simple online:

http://www.bin-co.com/php/scripts/xml2array/

I've only used it for internal xml files, so its worth a security audit if you're using external xml


simplexml_load_file() is really a good start for this. note here, $xml is not an array. if you want to save more records in your database, use it in a proper way. print_r($xml) will help you to get the better structure .

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜