Take the 2-minute tour ×

What is the problem with this code?

$feedURL = 'http://gdata.youtube.com/feeds/api/standardfeeds/US/most_viewed?v=2&time=all_time';
$site_url = 'http://localhost/';    
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$watch = $attrs['url'];  
$video_id = str_replace('http://www.youtube.com/watch?v=', '',$watch);
$video_id = str_replace('&feature=youtube_gdata', '',$video_id);
echo $details .= '

The code should return a list of 25 url's (via the youtube api feed) with the format:


But the code returns an ugly list of url's (whith the format i want) mixed and repeated.

PS: before str_replace the links were displayed correctly but with the format:


What's wrong? How can i resolve this?

share|improve this question
Can you maybe post the list of the received urls and the list of "ugly" urls you receive? –  Jan Vladimir Mostert Mar 19 '11 at 17:53

2 Answers 2

up vote 0 down vote accepted

echo $details .= '..'; $details is not defined before so use echo $details = '...'

share|improve this answer
thank you. i've didn't saw that. it seems that this was the problem. –  m3tsys Mar 19 '11 at 18:06

the last line is the problem: you add every entry to $details and echo it additionally. Just put

echo $details;

behind your loop and remove the echo in the loop, that's all. With your current code, you repeat the content by adding it to the variable AND echoing it.

share|improve this answer
thank you for this answer –  m3tsys Mar 19 '11 at 18:07

Your Answer


