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++;
	}

}

Recommended Answers

All 2 Replies

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>";
?>

Thanks that was it. I was so close.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.