Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:59:09+00:00 2026-06-15T01:59:09+00:00

I try to get rss, I get wrong data for some reason: $url =

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:59:10+00:00Added an answer on June 15, 2026 at 1:59 am

    You’re running against a Location snag.

    Add this option:

      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    

    so as to have:

    $url = "http://rss.news.yahoo.com/rss/oddlyenough";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $xml = curl_exec($ch);      
    curl_close($ch);
    echo htmlentities($xml, ENT_QUOTES, "UTF-8");
    

    Details

    When you run the above code, the first answer you receive from Yahoo! is:

    HTTP/1.0 301 Moved Permanently
    Date: Sun, 25 Nov 2012 16:31:36 GMT
    P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    Cache-Control: max-age=3600, public
    Location: http://news.yahoo.com/rss/oddlyenough
    Vary: Accept-Encoding
    Content-Type: text/html; charset=utf-8
    Age: 1586
    Content-Length: 81
    Via: HTTP/1.1 rc4.ops.ch1.yahoo.com (YahooTrafficServer/1.20.10 [cHs f ])
    Server: YTS/1.20.10
    
    <!-- rc4.ops.ch1.yahoo.com uncompressed/chunked Sun Nov 25 16:31:36 UTC 2012 -->
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to parse within my iPhone SDK 4 http://de.news.search.yahoo.com/news/rss?p=iphone&ei=UTF-8&fl=0&x=wrt there are some german
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
I try to use this example to get images urls from http://www.nydailynews.com/cmlink/NYDN.Article.rss but no
I try to get some website attribute (colour of the cell) and compare in
I try to get to a page straight from Bash at http://www.ocwconsortium.org/ . The
I'm trying to download a corpus of news (to try to do some natural
I'm trying to parse RSS feed from this link http://www.gazetaexpress.com/rss.php?cid=1,13&part=rss but when i try
I'm trying to retrieve a rss feed from this URL: http://www.8a.nu/rss/Main.aspx?UserId=19212&AscentType=0&ObjectClass=2&GID=3974d72911c05719152f0953e88cc2df There is no
for some reason I get this error below when trying to use multiple require()
I'm trying to UrlFetch the RSS/Atom feed from my site's news page posts URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.