我有变量$result
包含如下的 xml 字符串:
<reversegeocode timestamp="Mon, 12 Sep 16 07:52:44 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="format=xml&lat=30&lon=-95&addressdetails=1">
<result place_id="60369529" osm_type="way" osm_id="21077989" ref="County Road 6042" lat="30.0103064" lon="-95.0042308" boundingbox="30.0030833,30.0158095,-95.005969,-95.0038698">
County Road 6042, Sheeks, Liberty County, Texas, 77336, United States of America
</result>
<addressparts>
<road>County Road 6042</road>
<hamlet>Sheeks</hamlet>
<county>Liberty County</county>
<state>Texas</state>
<postcode>77336</postcode>
<country>United States of America</country>
<country_code>us</country_code>
</addressparts>
</reversegeocode>
我是 PHP 新手,需要插入变量城市(如果城市不存在城市 = 县)、州和邮政编码标签,仅在<addressparts>
标签下。所有剩余数据都可以忽略。我不知道该怎么做