How PHP takes data from XML

Source: Internet
Author: User
Tags cdata
How PHP takes data from XML
' Http://box.zhangmen.baidu.com/x?op=12&count=1&title= in the winter $$ Qi Qin $ $ '
This interface provides XML-formatted files, which I use $xml = file_get_contents (' http://box.zhangmen.baidu.com/x?op=12&count=1&title= about in winter $$ Qi Qin $ $ '); How to get the value inside the XML, ask PHP God to write some of the code for my reference, thank you very much.

  $xml = file_get_contents (' http://box.zhangmen.baidu.com/x?op=12&count=1&title= in the winter $$ Qi Qin $ $ ');
$result = simplexml_load_string ($xml);


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 ' peer ' =
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 to take
 
  
  
   
<br />http://zhangmenshiting.baidu.com/data2/music/64380827/ Z2zmbgvuaw9fn6nndk6ap5wxcghomgieazszagpvmgxly2tnz5ebawnpamaaazlrk2lqmzaxa3ctzjezmw1ncgvll1qin5t1ywbkbgvpb2tizgxqz2draje $<br>


<br />64380827.mp3?xcode=43b1f8bf459a441832ad12772e3b3b77eaa48b2ded70843d&mid=0.18038312962142<br>
Encode the data inside. What should I do, the value of that object (SimpleXMLElement) [5] is taken out.
------Solution--------------------
$xml = file_get_contents (' http://box.zhangmen.baidu.com/x?op=12&count=1&title= in the winter $$ Qi Qin $ $ ');

$result = simplexml_load_string ($xml, ' simplexmlelement ', libxml_nocdata);
Var_dump ($result->url->decode);

------Solution--------------------

$xml = file_get_contents (' http://box.zhangmen.baidu.com/x?op=12&count=1&title= in the winter $$ Qi Qin $ $ ');
$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
------Solution--------------------
XML = file_get_contents (' http://box.zhangmen.baidu.com/x?op=12&count=1&title= about in winter $$ Qi Qin $ $ ');
$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

  • Related Article

    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.