PHP怎么取XML中数据
Jun 13, 2016 am 11:51 AM
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 />
http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcJZtb5lsamRjaW2ZnJmTaWxraWmYcWdoa2drZ26ZaZhlmZaXa3CTZJeZmW1ncGVll1qin5t1YWBmbWlvcHFlZmxqaWttbDE$
64380827.mp3?xcode=b89b492058ceab79743a96683617a8f2eaa48b2ded70843d&mid=0.39499944964564
------解决方案--------------------
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 />

Artikel Panas

Alat panas Tag

Artikel Panas

Tag artikel panas

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6
Alat pembangunan web visual

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Topik panas

Penyelesaian: Organisasi anda memerlukan anda menukar PIN anda

Cara melaraskan tetapan sempadan tetingkap pada Windows 11: Tukar warna dan saiz

Bagaimana untuk menukar warna bar tajuk pada Windows 11?

Bagaimana untuk mendayakan atau melumpuhkan pratonton lakaran kecil bar tugas pada Windows 11

Masalah Ralat OOBELANGUAGE dalam Pembaikan Windows 11/10

Apakah perbezaan antara Huawei GT3 Pro dan GT4?

Paparkan panduan penskalaan pada Windows 11

10 Cara untuk Melaraskan Kecerahan pada Windows 11
