$string = 'id p="123456"654321/dd p="123456"654321/d/i';
成都創(chuàng)新互聯(lián)制作網(wǎng)站網(wǎng)頁找三站合一網(wǎng)站制作公司,專注于網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),網(wǎng)站設(shè)計,企業(yè)網(wǎng)站搭建,網(wǎng)站開發(fā),建網(wǎng)站業(yè)務(wù),680元做網(wǎng)站,已為千余家服務(wù),成都創(chuàng)新互聯(lián)網(wǎng)站建設(shè)將一如既往的為我們的客戶提供最優(yōu)質(zhì)的網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷推廣服務(wù)!
$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);
}
親手打的,經(jīng)過測試的,采納吧
?php
header("Content-type: text/html; charset=utf-8");
$xml = '?xml version="1.0" encoding="utf-8"?rss version="5.0"list page="1" pagecount="1" pagesize="20" recordcount="1"videolast2014-7-11 12:08:07/lastid19393/idtid7/tidname![CDATA[越軌追擊]]/nametype愛情/typepic;/piclang英語/langarea歐美/areayear2005/yearstate0/statenote![CDATA[HD]]/noteactor![CDATA[克里夫·歐文 詹妮弗·安妮斯頓]]/actordirector![CDATA[米凱爾·哈弗斯特羅姆]]/directordldd flag="jjvod"![CDATA[HD$jjhd://20000|b3a97575c3df592ec08adb93c54a9c2dcf7dc332|越軌追擊HD中字1280高清.rmvb$jjvod]]/dd/dldes![CDATA[他又無法求助于警察,他現(xiàn)在必須找到露辛達(dá),依靠兩個人的力量奪回曾經(jīng)寧靜的生活。]]/des/video/list/rss';
$result = simplexml_load_string($xml);
//var_dump($result); //可以打印看看結(jié)果如何
$result = object_to_array($result);
//print_r($result['list']['video']);exit;
foreach($result['list']['video'] as $key=$v){
echo $key."=".$v."\n";
}
function object_to_array($obj){
$arr = array();
$_arr = is_object($obj)? get_object_vars($obj) :$obj;
foreach ($_arr as $key = $val){
$val=(is_array($val)) || is_object($val) ? object_to_array($val) :$val;
$arr[$key] = $val;
}
return $arr;
}
?
先給你個以前寫的讀取xml格式的天氣預(yù)報的代碼吧,比著葫蘆畫瓢,不懂再追問
?php
$apistr=file_get_contents(";ak=B8aced94da0b345579f481a1294c9094");?//獲取xml內(nèi)容
$apiobj=simplexml_load_string($apistr);//解析xml代碼
$todayobj=$apiobj-results-result[0]-date;//讀取星期
$weatherobj=$apiobj-results-result[0]-weather;//讀取天氣
$windobj=$apiobj-results-result[0]-wind;//讀取風(fēng)力
$temobj=$apiobj-results-result[0]-temperature;//讀取溫度
$contentStr?=?"上海\n{$todayobj}\n天氣:{$weatherobj}\n風(fēng)力:{$windobj}\n溫度:{$temobj}";
echo?$contentStr;
?