Hey all,
Going off of what I did last week on the get_file_contents of a stock quote, a buddy of mine wondered if I could use PHP to pull a song name from his Shoutcast server site to display directly on his homepage.
Here's the skinny:
I'm trying to pull the 'Current Song' playing that's listed in this URL:PHP Code:<html>
<head>
<title>Current Song Playing</title>
</head>
<body>
<?php
// Set variables for the station URL and name
$stationurl = 'http://peatboxradio.darktech.org:8000/listen.pls';
$stationname = 'Peatbox Radio';
echo '<h1>Current Song Playing on '. $stationname . '</h1>';
// Get information
$theurl = 'http://peatboxradio.darktech.org:8000';
$contents = function_exists('file_get_contents') ? file_get_contents($theurl) : implode('', file($theurl));
if (!$contents) {
die('Unknown information');
}
$pattern = '~Current Song: </font></td><td><font class=default><b>(\$[a-z]+)</b> ~iUs';
if (preg_match($pattern, $contents, $match)) {
$currentsong = $match[1];
echo '<p> Current song playing is: <strong>' . $currentsong . '</strong></p>';
} else {
echo 'Could not retrieve value <br />';
}
// Acknowledge source
echo 'This information retrieved from <br />
<a href="'.$theurl.'">'.$theurl.'</a><br />
on ' . date('l jS F Y g:i a T');
?>
</body>
</html>
http://peatboxradio.darktech.org:8000/
I'm using file_get_contents to read in that page, however, it only works when I ditch the ':8000' from the URL, so I'm assuming there's issues w/ utilizing pages that are via certain ports. I know my code my be sketchy elsewhere (such as $pattern) but I just want to get past this port issue first. The above URL is the only way to get to the current song also.
I'm gonna head over to the Manual to see if I can find anything there, but wanted to post here to see if anyone has had issues w/ this before.
Ian





On Chapter 20 in the PHP/MySQL Web Development book.
Bookmarks