将XML数据提取到php [英] Extracting XML data to php

查看:91
本文介绍了将XML数据提取到php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从XML文件提取数据( http://freegeoip.net/xml/google .com ).您可以看到文件的内容类似于:

I'm trying to extract data from XML file (http://freegeoip.net/xml/google.com). You can see the content of the file looks something like:

<Response>
<Ip>74.125.235.3</Ip>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<RegionCode>CA</RegionCode>
<RegionName>California</RegionName>
<City>Mountain View</City>
<ZipCode>94043</ZipCode>
<Latitude>37.4192</Latitude>
<Longitude>-122.0574</Longitude>
<MetroCode>807</MetroCode>
<AreaCode>650</AreaCode>
</Response>

我想获取存储在<latitude><longitude>标记中的信息,并将它们存储在单独的变量中.问题是,我不知道该怎么做,并且想知道是否有人可以向我展示如何使用php解析XML文件?

I want to take the information stored in the <latitude> and <longitude> tags, and store them in separate variables. The problem is, I've little idea how to do this, and was wondering if anyone could show me how to parse XML files with php?

推荐答案

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

这篇关于将XML数据提取到php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆