0

我的 xml 飞行:

<item>
<title geoid="1198">District of Columbia</title>
<description cong_dist="Delegate District (at Large) 98">DC - Delegate District (at Large) 98 <br/> No of Incidents: 1436</description>
<latitude>38.8933115</latitude>
<longitude>-77.0146475</longitude>
<georss:polygon>38.934311 -77.1199 38.939834989364 -77.112868886998 38.94641 -77.1045 38.94891 -77.1007 38.95651 -77.0915 38.960871062931 -77.085827416011 38.967245703105 -77.077535703105 38.971616050926 -77.07185104194 38.98511 -77.054299 38.986557824794 -77.052373393024 38.99511 -77.040999 38.99171 -77.036299 38.98423067065 -77.026499658425 38.977828623846 -76.909395 38.895811472659 -76.913155644266 38.904084963804 -76.923528686655 38.904209815545 -76.923685221832 38.910455906543 -76.931516373827 38.913311 -76.935096 38.918592133391 -76.941928356721 38.930758817183 -76.957668751373 38.93511031877 -76.963298416241 38.946183221387 -76.977623754198 38.951906165093 -76.985027693844 38.95742281319 -76.992164742828 38.961159688178 -76.99699924729 38.96541 -77.002498 38.97011 -77.008298 38.97441 -77.013798 38.97591 -77.015598 38.977828623846 -77.018111761535 38.98423067065 -77.026499658425 38.99171 -77.036299 38.99511 -77.040999 38.986557824794 -77.052373393024 38.98511 -77.054299 38.971616050926 -77.07185104194 38.967245703105 -77.077535703105 38.960871062931 -77.085827416011 38.95651 -77.0915 38.94891 -77.1007 38.94641 -77.1045 38.939834989364 -77.112868886998 38.934311 -77.1199</georss:polygon>
</item>

我将此值存储在dc.xmlfile

如何获取变量中的所有值。例如标签值存储在 php 中的 $lat 变量中。

如何获得这个值我需要你的帮助......,

4

2 回答 2

2

试试这个

<?php
$string = <<<XML
<?xml version='1.0'?>
<item>
<title geoid="1198">District of Columbia</title>
<description cong_dist="Delegate District (at Large) 98">DC - Delegate District (at Large) 98 <br/> No of Incidents: 1436</description>
<latitude>38.8933115</latitude>
<longitude>-77.0146475</longitude>
<georss:polygon>38.934311 -77.1199 38.939834989364 -77.112868886998 38.94641 -77.1045 38.94891 -77.1007 38.95651 -77.0915 38.960871062931 -77.085827416011 38.967245703105 -77.077535703105 38.971616050926 -77.07185104194 38.98511 -77.054299 38.986557824794 -77.052373393024 38.99511 -77.040999 38.99171 -77.036299 38.98423067065 -77.026499658425 38.977828623846 -76.909395 38.895811472659 -76.913155644266 38.904084963804 -76.923528686655 38.904209815545 -76.923685221832 38.910455906543 -76.931516373827 38.913311 -76.935096 38.918592133391 -76.941928356721 38.930758817183 -76.957668751373 38.93511031877 -76.963298416241 38.946183221387 -76.977623754198 38.951906165093 -76.985027693844 38.95742281319 -76.992164742828 38.961159688178 -76.99699924729 38.96541 -77.002498 38.97011 -77.008298 38.97441 -77.013798 38.97591 -77.015598 38.977828623846 -77.018111761535 38.98423067065 -77.026499658425 38.99171 -77.036299 38.99511 -77.040999 38.986557824794 -77.052373393024 38.98511 -77.054299 38.971616050926 -77.07185104194 38.967245703105 -77.077535703105 38.960871062931 -77.085827416011 38.95651 -77.0915 38.94891 -77.1007 38.94641 -77.1045 38.939834989364 -77.112868886998 38.934311 -77.1199</georss:polygon>
</item>
XML;

$xml = simplexml_load_string($string);
$title = $xml->title;
print_r($title);
?>
于 2013-01-30T05:49:53.503 回答
1

看到这个屏幕截图,你所说的完全没有错误在此处输入图像描述

于 2013-01-30T06:16:52.213 回答