How does PHP retrieve XML data?

Source: Internet
Author: User
How does PHP retrieve XML data 'http: // box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = About Winter $ Qi Qin $'
This interface provides files in xml format. I use $ xml = file_get_contents ('http: // box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = About $ $ 'in winter); how can I get the values in xml after obtaining them, I am grateful for writing some code for my reference.

$ Xml = file_get_contents ('http: // box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = About $ $ ') in winter; $ result = simplexml_load_string ($ xml); var_dump ($ result );


Print results
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)


I want
 http://zhangmenshiting.baidu.com/data2/music/64380827/Z2ZmbGVuaW9fn6NndK6ap5WXcGhomGieaZSZaGpvmGxlY2tnZ5ebaWNpamaaaZlrk2lqmZaXa3CTZJeZmW1ncGVll1qin5t1YWBkbGVpb2tiZGxqZ2drajE$
 
 64380827.mp3?xcode=43b1f8bf459a441832ad12772e3b3b77eaa48b2ded70843d&mid=0.18038312962142
 
The data in the encode .. What should I do? how can I obtain the value of the object (SimpleXMLElement) [5 ..


Reply to discussion (solution)

$ Xml = file_get_contents ('http: // box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = About $ $ '); $ 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 = About $ $ '); $ result = simplexml_load_string ($ xml, 'simplexmlelement', LIBXML_NOCDATA ); $ ret = (array) $ result-> url; echo $ ret ['encoding']."
"; Echo $ ret ['decode'];


Bytes
64213827133? Xcode = b89b492058ceab79743a96683617a8f2eaa48b2ded70843d & mid = 0.39499944964564

Xml = file_get_contents ('http: // box.zhangmen.baidu.com/x? Op = 12 & count = 1 & title = About $ $ '); $ 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

Baidu knows that someone has already answered the question and implemented it using DOM. it doesn't feel as easy as you write. Because I don't know PHP syntax, so this is a simple problem .. Everybody is right. close the score.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.