Extracting XML data to php

This question already has an answer here:

  • How do you parse and process HTML/XML in PHP? 28 answers

  • $string_data = "<your xml response>";
    $xml = simplexml_load_string($string_data);
    $latitude = (string) $xml->Latitude;
    $longitude = (string) $xml->Longitude;
    echo $latitude.' '.$longitude;
    

    很简单,使用PHP的SimpleXML库:

    $xml = simplexml_load_file("http://freegeoip.net/xml/google.com");
    echo $xml->Ip; // 173.194.38.174
    echo $xml->CountryCode; // US
    echo $xml->ZipCode; // 94043
    // etc...
    

    The PHP manual has a whole section on PHP parsing:

  • http://php.net/manual/en/book.simplexml.php
  • http://php.net/manual/en/book.xml.php
  • For simplicity, you could also use xml_parse_into_struct()

    Here's a pretty good example, using SimpleXML:

    http://blog.teamtreehouse.com/how-to-parse-xml-with-php5

    链接地址: http://www.djcxy.com/p/29906.html

    上一篇: 正则表达式在php中获取div类的内容

    下一篇: 将XML数据提取到php