Jump to content

URGENT: using cURL to get RSS Feed fails - think I am really close... help!


adentone

Recommended Posts

I am creating this feature for a client of mine that needs it working by tomorrow!

 

I am trying to use cURL to grab the RSS feed here:

http://blogs.menshealth.com/fitness-pros/feed

 

But all I get back is an empty string...

Please help - I've been searching Google & this forum but haven't found anything that I can use that fixes this issue.

 

$feed = getRssData();
echo "<pre>\n";
print_r( $feed );
echo "\n</pre>\n";

function getRssData() { // returns the feed array
$requested_feed = "http://blogs.menshealth.com/fitness-pros/feed";
$ch = curl_init($requested_feed);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$rss_data = curl_exec($ch);
curl_close($ch);
echo "RSS DATA: <br />\n" . $rss_data;
$doc = new DOMDocument();
$doc->load($rss_data);
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
	$itemRSS = array ( 
		'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
		'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
		'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
		'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
	);
	array_push($arrFeeds, $itemRSS);
}
return $arrFeeds;
}

 

You can see a live test here:

http://pro-formpt.com/get_rss.php?feed=workout

It only has a few parameters in it so I can use the same file to grab other RSS Feeds as well - but they all fail the same way.

Like this one:

http://pro-formpt.com/get_rss.php?feed=living

Which should grab the feed from here:

http://blogs.menshealth.com/mh-life/feed

 

I truly appreciate any suggestions!

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.