Home >Backend Development >PHP Tutorial >curl获取xml数据的有关问题

curl获取xml数据的有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:11:35962browse

curl获取xml数据的问题
我用curl获取xml文件链接,得到的只有内容,而没有结构。

比如:123red

得到的就是:123 red  

请问是需要设置哪里吗?
------解决思路----------------------
贴出代码看看。
------解决思路----------------------
你只是获取到了值并没有对生成的XML进行解析,所以肯定不会得到你要的效果。
------解决思路----------------------
在输出前加个header。

<br />function curlxml($url){<br />    $header[] = "Content-type: text/xml";//定义content-type为xml<br />    $ch = curl_init();  <br />    curl_setopt($ch, CURLOPT_URL, $url);  <br />    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);<br />    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);<br />    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回    <br />    $r = curl_exec($ch);  <br />    curl_close($ch); <br />         <br />    return $r;    <br />    }<br />     <br /> $url="https://www.123456.com";<br />  <br /> $value=curlxml($url);<br /> <br />header('content-type:text/xml;charset=utf-8');<br /> echo $value;  <br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn