比如: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文件包括结构,我自己解决了,谢谢了
