Curl gets the XML data problem

Source: Internet
Author: User
I use curl to get the XML file link, get only the content, and no structure.

Like what: 123 Red

What you get is: 123 red

Would you like to set where?


Reply to discussion (solution)

Post the code to see.

function Curlxml ($url) {    $header [] = "content-type:text/xml";//define Content-type as XML    $ch = Curl_init ();      curl_setopt ($ch, Curlopt_url, $url);      curl_setopt ($ch, curlopt_useragent, $_server[' http_user_agent ');    curl_setopt ($ch, Curlopt_httpheader, $header);    curl_setopt ($ch, Curlopt_binarytransfer, true); Get Data back        $r = curl_exec ($ch) when Curlopt_returntransfer is enabled;      Curl_close ($ch);             return $r;        }     $url = "https://www.123456.com";  $value =curlxml ($url); Echo $value;  


Because the links are generated temporarily, so there is no way to take up the test, please help me to see if it is also set where, thank you!

You just get the value and don't parse the generated XML, so you certainly won't get the effect you want.

Add a header before the output.

function Curlxml ($url) {    $header [] = "content-type:text/xml";//define Content-type as XML    $ch = Curl_init ();      curl_setopt ($ch, Curlopt_url, $url);      curl_setopt ($ch, curlopt_useragent, $_server[' http_user_agent ');    curl_setopt ($ch, Curlopt_httpheader, $header);    curl_setopt ($ch, Curlopt_binarytransfer, true); Get Data back        $r = curl_exec ($ch) when Curlopt_returntransfer is enabled;      Curl_close ($ch);              return $r;        }      $url = "https://www.123456.com";   $value =curlxml ($url); Header (' Content-type:text/xml;charset=utf-8 '); Echo $value;  

Thank you upstairs, maybe I did not express clearly, I want to get the whole XML file including structure, I solved it myself, thank you

  • 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.