PHP Code to display the current song and number of listeners of a shoutcast server

To help out those of you with shoutcast stations and want to show them off! You can use this code in Drupal or any CMS or page that accepts PHP code. Just fill in the IP address of your shoutcast server and the port in which it listens on and this script will output the current song and the number of listeners. There are variations of it floating around the internet. Its weakness is that if your song contains any commas (,) then the song title will stop at the comma.

<?php
$ip = "127.0.0.1";
$port = "8000";
$fp = @fsockopen($ip,$port,$errno,$errstr,1);
if (!$fp)
{
echo "Connection refused"; // Diaplays when sever is offline
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('', "", $info);
$split = explode(',', $info);
if (empty($split[6]) )
{
echo "The current song is not available"; // Displays when sever is online but no song title
}
else
{
$title = str_replace('\'', '`', $split[6]);
$title = str_replace(',', ' ', $title);
echo "$title -  Listeners: $split[0]"; // Displays song
}
}
?>

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments 3

  1. sasderwn wrote:

    Hello World

    Posted 12 Apr 2009 at 9:33 pm
  2. ChabrellIgan wrote:

    God dag! Kan jag ladda ner en bild fran din blogg. Av sak med hanvisning till din webbplats!

    Posted 19 Apr 2009 at 12:57 am
  3. RayRay wrote:

    God dag! Det krävs för att översätta din kommentar. Vilken bild vill du länka till? Om du tar webbadressen för bilden och lägga till ordet snabbt istället för www, så får du en bild snabbt utan några dåliga effekter för mig. Du kan också använda någon av mina fria gallerier! http://www.cyborgcow.net & http://www.hardcoredreamer.com/gallery/

    Posted 19 Apr 2009 at 1:01 pm

Post a Comment

Your email is never published nor shared. Required fields are marked *

Improve the web with Nofollow Reciprocity.