0

I have this foreach loop that loops through the title and link of an xml file. I want to be able to sperate the title and put it into an array or assign each title to a variable. I also want to do the same thing with the link. Could any body help me out.

Here is my code.

<?php // Load and parse the XML document 
$rss =  simplexml_load_file('http://www.ubcmiami.org/podcasts/podcast.xml');
$title =  $rss->channel->title;

// Here we'll put a loop to include each item's title and link
foreach ($rss->channel->item as $item) {
	if($count <= 4)
	{

		$media_link = $item->guid;
		$media_title = $item->title;
  		$count++;
	}

}
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by alexgv14
0

You have done 99% of the work already. You just have to use [] with $media_link and $media_title.

<?php // Load and parse the XML document 
$rss =  simplexml_load_file('http://www.ubcmiami.org/podcasts/podcast.xml');
$title =  $rss->channel->title;

// Here we'll put a loop to include each item's title and link
foreach ($rss->channel->item as $item) {
	if($count <= 4)
	{

		$media_link[] = $item->guid;
		$media_title[] = $item->title;
  		$count++;
	}

}
print "<pre>";
print_r($media_link);
print_r($media_title);
print "</pre>";
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.