PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Tue Jun 09, 2009 1:42 am
I found this code to help me get started in parsing RSS feed and extract the basic information I wanted. However, I have tried and tried and tried to parse the <enclosure> tag to extract the url, length and type but no success. What do you suggest I should add to the code below to get the enclosure information?
Code: Select all
$doc = new DOMDocument();
$doc->load('http://davebender.podbean.com/feed/');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
$itemRSS = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
I appreciate your help.
Last edited by
Benjamin on Wed Jun 10, 2009 11:55 am, edited 1 time in total.
Reason: Changed code type from text to php.
RishikeshJha
Forum Newbie
Posts: 11 Joined: Tue Mar 31, 2009 1:54 am
Post
by RishikeshJha » Tue Jun 09, 2009 1:50 am
hi,
use this code in your code:
put this code at the start of the code...
put this code after your own code...
Code: Select all
$myArray[++$index]['title']=$itemRSS['title'];
$myArray[$index]['desc']=$itemRSS['desc'];
$myArray[$index]['link']=$itemRSS['link'];
$myArray[$index]['date']=$itemRSS['date'];
finally return $myArray
Last edited by
Benjamin on Wed Jun 10, 2009 11:56 am, edited 1 time in total.
Reason: Added [code=php] tags.
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Wed Jun 10, 2009 6:31 am
I have no problem of getting those variables. But what I want from the feed is the <enclosure> tag which have three elements: url, length and type. I don't know how to extract the enclosure tag. Any idea?
mikemike
Forum Contributor
Posts: 355 Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK
Post
by mikemike » Wed Jun 10, 2009 7:33 am
Without knowing the strucutre of the XML file...
$node->getElementsByTagName('enclosure')->item(0)->nodeValue; perhaps?
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Wed Jun 10, 2009 9:35 am
I had tried that before I turned to the forum for help. It did not work.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Jun 10, 2009 11:16 am
Maybe use an RSS library like SimplePie?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Wed Jun 17, 2009 9:29 pm
I really like the script I found. It is all very simple and works great. I wish I knew how to modify it to extract the ENCLOSURE tag.
Thanks for mentioning SimplePie. I am checking it out.
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Thu Jun 25, 2009 7:02 pm
I am just testing the example file from simplepie. It got an error on line 13104 in simplepie.inc.