本文目錄一覽:
- 1、php解析XML問題
- 2、xml php問題
- 3、PHP Xml解析中的問題
- 4、php跟xml有什麼關係
php解析XML問題
$string = ‘id p=”123456″654321/dd p=”123456″654321/d/i’;
$xmlObject = simplexml_load_string($string);
$result = array();
if($xmlObject) {
$i = 0;
foreach($xmlObject-d as $key = $value) {
$result[$i][$key] = $value-__toString();
foreach ($value-attributes() as $attr = $data) {
$result[$i][$attr] = $data-__toString();
}
++$i;
}
print_r($result);
}
xml php問題
因為 XML 文檔中只允許一個 根元素 。
simplexml 再為它聲明一個屬性就是多餘的操作了。
PHP Xml解析中的問題
xml格式組織不對。
weather_data下面的元素應該再分一層才可以,現在的格式並不能區分每個日期,可以這樣:
CityWeatherResponse
error0/error
statussuccess/status
date2015-03-24/date
results
currentCity鄭州/currentCity
weather_data
data
date周二 03月24日 (實時:14℃)/date
weather小雨/weather
wind微風/wind
temperature10℃/temperature
/data
data
date周三/date
weather陰轉小雨/weather
wind微風/wind
temperature16 ~ 9℃/temperature
/data
data
date周四/date
weather陣雨轉多雲/weather
wind微風/wind
temperature15 ~ 7℃/temperature
/data
data
date周五/date
weather晴/weather
wind風/wind
temperature10℃/temperature
/data
/weather_data
/results
/CityWeatherResponse
遍歷:
foreach($xml-results-weather_data-data as $exml)
{
echo $exml-date.”br”;
}
php跟xml有什麼關係
PHP屬於服務端網路編程語言,可以用於創建Web應用程序。
XML屬於一種標記語言,通常用於當作數據存儲的載體。
可以這麼說,使用PHP可以操作XML進行讀寫操作,XML是PHP操作的對象(之一)。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/155253.html