<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tom's 103 Analysis</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
/* Author: Tom Hacquoil
Date: 25th August 2010 */
/* PART 1: Get currently playing song and artist. */
# Put the contents of the source of the destination website into a 'content' variable.
$content = file_get_contents('http://www.channel103.com/music/index.php?qty=50');
# Using Regular Expressions, scan the file and everytime a match occurs, put data into the 'data' array.
preg_match('#<div><span>now playing – </span><a href="http://www.channel103.com/music/index.php">(.*)</a><span>(.*)</span></div>#', $content, $data);
# Assign the contents of the 'data' array to two variables, song and artist.
$song = $data[1];
$artist = $data[2];
# Print the content of those variables.
echo "<strong>Song:</strong> $song - <strong>Artist:</strong> $artist\n";
echo "<br /><br />";
/* PART 2: Get a list of all recently played songs. */
# Put the contents of the source of the destination website into a 'content' variable.
$content = file_get_contents('http://www.channel103.com/music/index.php?qty=20333');
# Using Regular Expressions, scan the file and everytime a match occurs, put data into the 'data' array.
preg_match('#<tr class="tabletextRow1"><td>(.*)</td>#', $content, $data);
# Print first entity of the array (for testing).
echo $data[1];
echo "<br /><br /><br />";
# Print the entire array. (For testing).
print_r($data);
?>
</body>
</html>
|