I try to get rss, I get wrong data for some reason:
$url = "http://rss.news.yahoo.com/rss/oddlyenough";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$xml = curl_exec($ch);
curl_close($ch);
echo htmlentities($xml, ENT_QUOTES, "UTF-8");
The output:
<!-- rc2.ops.ch1.yahoo.com uncompressed/chunked Sun Nov 25 15:57:06 UTC 2012 -->
If I try to load this data other way I get correct data. For example this one works:
$xml = simplexml_load_file('http://rss.news.yahoo.com/rss/oddlyenough');
print "<ul>\n";
foreach ($xml->channel->item as $item){
print "<li>$item->title</li>\n";
}
print "</ul>";
Could you please tell me what’s the problem with code using curl?
You’re running against a
Locationsnag.Add this option:
so as to have:
Details
When you run the above code, the first answer you receive from Yahoo! is:
and it tells you to use the new address http://news.yahoo.com/rss/oddlyenough.
Actually, if you use directly the new address, your original code works (until they change the address again, that is…) and is a bit faster, making only one request instead of two.