2025年01月16日 建站教程
如何利用php语法将访问的XML文件直接转换成数组格式,下面web建站小编给大家简单介绍一下具体实现代码!
$xmlObj = simplexml_load_file("city.xml"); $cityArray = array(); foreach ($xmlObj->channel->item as $item) { $titleArray = explode(" / ", $item->title); $city = $titleArray[0]; $temp = substr($titleArray[1], 0, 2); $cityArray[$city] = array("temperature" => $temp); } foreach ($cityArray as $city => $data) { echo "$city 的温度为:{$data['temperature']}度。"; }
本文链接:http://so.lmcjl.com/news/21452/