Question

Right now I am running a radio server and I set up a WordPress blog for it.

I made it auto refresh the widget by including it in an iframe that auto refreshes every 10 seconds.

However, I have a programming issue. Whenever it has a "-" in the song name ($artist[2]), it automatically puts it into the next one ($artist[3])

Here is my code for the php file: http://fonts.googleapis.com/css?family=Merriweather+Sans:400,700' rel='stylesheet' type='text/css'> p { font-family: 'Merriweather Sans', sans-serif; font-weight: 400; } b { font-family: 'Merriweather Sans', sans-serif; font-weight: 700; }

<?php header("Refresh: 10")>

//Display IceCast Server Stats

$server = "direct.x86cam.com"; //IP (x.x.x.x or domain name)
    $iceport = "8000"; //Port
$iceurl = "stream.mp3"; //Mountpoint
    $online = "<font color=green><b>ONLINE</b> </font><br />";
    $offline = "<font color=red><b>OFFLINE</b></font><br />";

    if($fp = @fsockopen($server, $iceport, $errno, $errstr, '1')) {
            fclose($fp);
            $ice_status=$online;
            echo "<p><b>Stream Status:</b> $ice_status";
            $stats = file("http://" . $server . ":" . $iceport . "/status2.xsl");
            $status = explode(",", $stats[5]);
            $artist = explode("-", $status[5]);
    echo "<b>Artist:</b> " . $artist[1];
            echo "<b>Song:</b> " . $artist[2];
    echo "<br />";
            echo "<b>Listeners:</b> <b> " . $status[3] . "</b>";
            echo "</p>";
    //echo "<br />";
    //echo "<p><a href=http://" . $server . ":" . $iceport . "/" . $iceurl . " target=new><b>Listen!</b></a></p>";

     } else {

            $ice_status=$offline;
            echo "<p><b>Stream Status:</b> $ice_status";
    }

?>
<hr />
</center>

Can anyone please explain how I could fix this?

Was it helpful?

Solution

The problem must lie in $artist = explode("-", $status[5]), If an artist name or song name contains '-', it will be exploded as well.

If you could change the source xsl, please put artist and song in different nodes, <artist>An-Artist</artist> <song>A-Song</song>, it wont be a problem in separation using php xml parse.

Otherwise, you may have to put artist and song name together

  $status = explode(",", $stats[5]);
  $artist = substr($status[5], 3); //remove '-'
  echo "<b>Artist-Song:</b> " . $artist;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top