如何从此代码加载xml [英] how to load xml from this code please
本文介绍了如何从此代码加载xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从此xml代码加载内部值:
I want to load the inside values from this xml code:
<?xml version="1.0" encoding="UTF-8"?>
<geoPlugin>
<geoplugin_city>Salt Lake City</geoplugin_city>
<geoplugin_region>UT</geoplugin_region>
<geoplugin_areaCode>801</geoplugin_areaCode>
<geoplugin_dmaCode>770</geoplugin_dmaCode>
<geoplugin_countryCode>US</geoplugin_countryCode>
<geoplugin_countryName>United States</geoplugin_countryName>
<geoplugin_continentCode>NA</geoplugin_continentCode>
<geoplugin_latitude>40.700199127197</geoplugin_latitude>
<geoplugin_longitude>-111.94339752197</geoplugin_longitude>
<geoplugin_regionCode>UT</geoplugin_regionCode>
<geoplugin_regionName>Utah</geoplugin_regionName>
<geoplugin_currencyCode>USD</geoplugin_currencyCode>
<geoplugin_currencySymbol>$</geoplugin_currencySymbol>
<geoplugin_currencyConverter>1</geoplugin_currencyConverter>
</geoPlugin>
如果您可以看到geoplugin_city等我想将这些值加载到php
If you can see the geoplugin_city, etc I want to load these values to php
$location = 'http://www.geoplugin.net/xml.gp?ip='.$_SERVER['REMOTE_ADDR'];
$xml = simplexml_load_file($location);
那没用.请帮帮我.
opps php ment xml
opps php i ment xml
推荐答案
首先将代码更改为此
$location = 'http://www.geoplugin.net/xml.gp?ip='.$_SERVER['REMOTE_ADDR'];
$xml = simplexml_load_file($location);
然后,进行一个 Foreach
循环以获取其中的所有数据.
After that, make a Foreach
loop to have all the data from that.
foreach ($xml as $keys => $values) {
$data[] = $values; // $data array have all your data independently.
}
现在,打印数组并测试值.
Now, print the array and test the values.
echo "<pre>"; print_r($data); echo "</pre>";
但是,请尝试转储变量,以便您也可以获取数据类型.
However, try for dumping the variables so you will get the data types too..
var_dump($xml);
这篇关于如何从此代码加载xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文