我需要从此网址检索XML内容:
http://www.ardmasr.com/MasrenaRss.aspx?Category=4
总是返回一个没有任何错误的空字符串,代码:
$curl = curl_init();
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt ($curl, CURLOPT_USERAGENT,'smartic-rss-feeds');
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_TIMEOUT,120);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
if($curlFollowRedirects){
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
}
$content = curl_exec($curl);
// Check if any error occurred
if($content === false)
{
echo 'Curl error: ' . curl_error($curl);
}
curl_close ($curl);
// if there is a redirect
if(preg_match('#Location: (.*)#',$content, $r)){
$l = trim($r[1]);
$content = $this->fetch_data($l);
}
return $content;
答案 0 :(得分:0)
我在编码URL时遇到的问题我用这个函数来解决我的问题:
utf8_decode($url)