您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

curl获取xml数据的问题

2024/2/24 19:22:40发布14次查看
我用curl获取xml文件链接,得到的只有内容,而没有结构。
比如:123red
得到的就是:123 red
请问是需要设置哪里吗?
回复讨论(解决方案) 贴出代码看看。
function curlxml($url){ $header[] = content-type: text/xml;//定义content-type为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) ; // 在启用 curlopt_returntransfer 时候将获取数据返回 $r = curl_exec($ch); curl_close($ch); return $r; } $url=https://www.123456.com; $value=curlxml($url); echo $value;
因为链接都是临时生成的,所以没办法拿上来测试,请帮我看看是不是还要设置哪里,谢谢!
你只是获取到了值并没有对生成的xml进行解析,所以肯定不会得到你要的效果。
在输出前加个header。
function curlxml($url){ $header[] = content-type: text/xml;//定义content-type为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) ; // 在启用 curlopt_returntransfer 时候将获取数据返回 $r = curl_exec($ch); curl_close($ch); return $r; } $url=https://www.123456.com; $value=curlxml($url); header('content-type:text/xml;charset=utf-8'); echo $value;
谢谢楼上的,可能我没表达清楚,我是想让$r获得整个xml文件包括结构,我自己解决了,谢谢了
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product