PDA

View Full Version : A little PHP help please


arpana
12-20-2007, 05:43 PM
Hi all,

I am using the songs.php plugin but would like to ammend how the song information is output. As it stands it just outputs in a continuous line, I would like to make it output as an unordered list.

I have virtually no PHP experience although I have (somehow) managed to work out where the <ul></ul> goes but unsure how to add the <li></li>, can anyone offer any guidance please?

Here is the code:


// Try to load and parse RSS file
// http://www.techie-blog.com/rss.php?blogId=1&profile=rss090
// http://ws.audioscrobbler.com/rss/recent.php?user=name_here
if ($rs = $rss->Get('http://ws.audioscrobbler.com/rss/recent.php?user=name_here', 10)) {
// Show last published articles (title, link, description)
$ctr = 1;
foreach($rs['items'] as $item) {
// formatting
$html .= "$ctr) ";

$html .= $item['title'];

// formatting
$html .= "&nbsp;&nbsp;//&nbsp;&nbsp;";
$ctr++;
}

// strip the last slashes
$html = ereg_replace("//&nbsp;&nbsp;$", "", $html);

if (!$html) $html = "Sorry - I've not got any recently played songs - come back soon.";

$tpl = ereg_replace("<MY_SONGS>","<ul class=\"pp-songs\">\n".$html."</ul>\n",$tpl);
}
else {
$tpl = ereg_replace("<MY_SONGS>","Sorry - either I've not listened to any songs recently, or there's trouble collecting the feed of songs over the Net, either way, there's nought to be seen here.\n",$tpl);
}

Thanks
Arpi

dakwegmo
12-20-2007, 06:10 PM
Try changing this line:
$html .= $item['title'];

To this:
$html .= "<li>" . $item['title'] . "</li>";

arpana
12-20-2007, 06:23 PM
Darn, that didn't work. Thanks anyway :)

dakwegmo
12-20-2007, 07:07 PM
Try this:

// Try to load and parse RSS file
// http://www.techie-blog.com/rss.php?b...profile=rss090
// http://ws.audioscrobbler.com/rss/rec...user=name_here
if ($rs = $rss->Get('http://ws.audioscrobbler.com/rss/recent.php?user=name_here', 10)) {
// Show last published articles (title, link, description)

foreach($rs['items'] as $item) {
// formatting
$html .= "<li>";

$html .= $item['title'];

// formatting
$html .= "</li>\n";

}


if (!$html) $html = "Sorry - I've not got any recently played songs - come back soon.";

$tpl = ereg_replace("<MY_SONGS>","<ul class=\"pp-songs\">\n".$html."</ul>\n",$tpl);
}
else {
$tpl = ereg_replace("<MY_SONGS>","Sorry - either I've not listened to any songs recently, or there's trouble collecting the feed of songs over the Net, either way, there's nought to be seen here.\n",$tpl);
}


Sorry I can't test this, I don't have a feed that works. If you have a feed that I can use to test I would be able to make sure it works before posting.

arpana
12-20-2007, 07:13 PM
Hey, that code did the trick :)

You are a shining star, thank you so much :)

The whole script is here: http://www.pixelpost.org/extend/addons/songs/

Arpy

dakwegmo
12-20-2007, 07:21 PM
I just tested that last bit of code and it works.