有沒有簡單的方法將xml文件標籤轉換爲一行?我的XML文件($xml = simplexml_load_file('http://localhost/locations.xml');
)包含:將xml標籤合併爲一個
<markers>
<marker>
<name>Chipotle Minneapolis</name>
<lat>44.947464</lat>
<lng>-93.320826</lng>
<category>Restaurant</category>
<address>3040 Excelsior Blvd</address>
<address2></address2>
<city>Minneapolis</city>
<state>MN</state>
<postal>55416</postal>
<country>US</country>
<phone>612-922-6662</phone>
<email>[email protected]</email>
<web>http://www.chipotle.com</web>
<hours1>Mon-Sun 11am-10pm</hours1>
<hours2></hours2>
<hours3></hours3>
<featured></featured>
</marker>
</markers>
轉換上面的代碼格式:
<markers><marker name="Chipotle Minneapolis" lat="44.947464" lng="-93.320826" category="Restaurant" address="3040 Excelsior Blvd" address2="" city="Minneapolis" state="MN" postal="55416" country="US" phone="612-922-6662" email="[email protected]" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" /></markers>
感謝
關於'unset($ c [0])'和其他刪除元素的方法,請閱讀以下內容:[在SimpleXML for PHP中刪除具有特定屬性的子項](http://stackoverflow.com/questions/262351/remove-a-child-with-a-specific-attribute-in-simplexml-for-php/16062633#16062633) – sidyll
此代碼有額外的空間。 – MahdiY