PHP如何取XML中数据
'http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$'
这个接口提供了xml格式的文件,我用$xml = file_get_contents ( 'http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');取出来xml后如何得到里面的值,求PHP大神写出部分代码给我参考,感激不尽。
$xml = file_get_contents('http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');<br /> $result = simplexml_load_string($xml);<br /> var_dump($result);
object(SimpleXMLElement)[1]<br /> public 'count' => string '1' (length=1)<br /> public 'url' => <br /> object(SimpleXMLElement)[2]<br /> public 'encode' => <br /> object(SimpleXMLElement)[5]<br /> public 'decode' => <br /> object(SimpleXMLElement)[6]<br /> public 'type' => string '8' (length=1)<br /> public 'lrcid' => string '14706' (length=5)<br /> public 'flag' => string '1' (length=1)<br /> public 'durl' => <br /> object(SimpleXMLElement)[3]<br /> public 'encode' => <br /> object(SimpleXMLElement)[7]<br /> public 'decode' => <br /> object(SimpleXMLElement)[8]<br /> public 'type' => string '8' (length=1)<br /> public 'lrcid' => string '14706' (length=5)<br /> public 'flag' => string '1' (length=1)<br /> public 'p2p' => <br /> object(SimpleXMLElement)[4]<br /> public 'hash' => string 'd1cae9f7634c5aa3d54d7b1b1ad4c5b79b6e97ff' (length=40)<br /> public 'url' => <br /> object(SimpleXMLElement)[9]<br /> public 'type' => string 'mp3' (length=3)<br /> public 'size' => string '5710896' (length=7)<br /> public 'bitrate' => string '192' (length=3)
<encode><br /><![CDATA[<br />http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcGhomGieaZSZaGpvmGxlY2tnZ5ebaWNpamaaaZlrk2lqmZaXa3CTZJeZmW1ncGVll1qin5t1YWBkbGVpb2tiZGxqZ2drajE$<br />]]><br /></encode><br /><decode><br /><![CDATA[<br />64380827.mp3?xcode=43b1f8bf459a441832ad12772e3b3b77eaa48b2ded70843d&mid=0.18038312962142<br />]]><br /></decode>
$xml = file_get_contents('http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');<br /> <br /> $result = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);<br /> var_dump($result->url->decode);
<br />$xml = file_get_contents('http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');<br />$result = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);<br />$ret = (array)$result->url;<br />echo $ret['encode']."<br/>";<br />echo $ret['decode'];<br />
xml = file_get_contents('http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');<br />$result = simplexml_load_string($xml);<br />echo strval($result->url->encode);<br />echo strval($result->url->decode);<br />
http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcGVpZpuaZJdrbGtqmm1mY2lolppnmpSXZWZubZyclmlmmZaXa3CTZJeZmW1ncGVll1qin5t1YWBmbGxsamxlaGVrbG9taTE$<br />64380827.mp3?xcode=140db3e8864c55164ad0bce2297ede73eaa48b2ded70843d&mid=0.38763446277961<br />