PHP怎么取XML中数据
程序员文章站
2022-05-17 14:54:13
...
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大神写出部分代码给我参考,感激不尽。
打印结果
我想取
------解决方案--------------------
------解决方案--------------------
http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcJZtb5lsamRjaW2ZnJmTaWxraWmYcWdoa2drZ26ZaZhlmZaXa3CTZJeZmW1ncGVll1qin5t1YWBmbWlvcHFlZmxqaWttbDE$
64380827.mp3?xcode=b89b492058ceab79743a96683617a8f2eaa48b2ded70843d&mid=0.39499944964564
------解决方案--------------------
'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=大约在冬季$$齐秦$$$$');
$result = simplexml_load_string($xml);
var_dump($result);
打印结果
object(SimpleXMLElement)[1]
public 'count' => string '1' (length=1)
public 'url' =>
object(SimpleXMLElement)[2]
public 'encode' =>
object(SimpleXMLElement)[5]
public 'decode' =>
object(SimpleXMLElement)[6]
public 'type' => string '8' (length=1)
public 'lrcid' => string '14706' (length=5)
public 'flag' => string '1' (length=1)
public 'durl' =>
object(SimpleXMLElement)[3]
public 'encode' =>
object(SimpleXMLElement)[7]
public 'decode' =>
object(SimpleXMLElement)[8]
public 'type' => string '8' (length=1)
public 'lrcid' => string '14706' (length=5)
public 'flag' => string '1' (length=1)
public 'p2p' =>
object(SimpleXMLElement)[4]
public 'hash' => string 'd1cae9f7634c5aa3d54d7b1b1ad4c5b79b6e97ff' (length=40)
public 'url' =>
object(SimpleXMLElement)[9]
public 'type' => string 'mp3' (length=3)
public 'size' => string '5710896' (length=7)
public 'bitrate' => string '192' (length=3)
我想取
encode里面的数据。。请问该怎么办,那个object(SimpleXMLElement)[5]的值怎么取出来。。
http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcGhomGieaZSZaGpvmGxlY2tnZ5ebaWNpamaaaZlrk2lqmZaXa3CTZJeZmW1ncGVll1qin5t1YWBkbGVpb2tiZGxqZ2drajE$
]]>
64380827.mp3?xcode=43b1f8bf459a441832ad12772e3b3b77eaa48b2ded70843d&mid=0.18038312962142
]]>
------解决方案--------------------
$xml = file_get_contents('http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');
$result = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
var_dump($result->url->decode);
------解决方案--------------------
$xml = file_get_contents('http://box.zhangmen.baidu.com/x?op=12&count=1&title=大约在冬季$$齐秦$$$$');
$result = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$ret = (array)$result->url;
echo $ret['encode']."
";
echo $ret['decode'];
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=大约在冬季$$齐秦$$$$');
$result = simplexml_load_string($xml);
echo strval($result->url->encode);
echo strval($result->url->decode);
http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcGVpZpuaZJdrbGtqmm1mY2lolppnmpSXZWZubZyclmlmmZaXa3CTZJeZmW1ncGVll1qin5t1YWBmbGxsamxlaGVrbG9taTE$
64380827.mp3?xcode=140db3e8864c55164ad0bce2297ede73eaa48b2ded70843d&mid=0.38763446277961
相关文章
相关视频
上一篇: C# 根据列名与列值设置当前行
下一篇: 没问号参数的地址是什么技术