Skip to content

Instantly share code, notes, and snippets.

@danmilleruk
Created February 21, 2012 14:24
Show Gist options
  • Save danmilleruk/1876772 to your computer and use it in GitHub Desktop.
Save danmilleruk/1876772 to your computer and use it in GitHub Desktop.
Grabs the tshock counts and places them inside a tag for use on webnumbr.
<?PHP
// Grab the data.
$page = @file_get_contents("http://tshock.co/count.php");
// A little error handling.
if($page == FALSE)
{
echo "Cannot retrieve data, exiting.";
die ();
}
// Here we explode the data, using <h4> as the delimiter.
$split_data = explode("<h4>", $page);
// Next we replace a series of data to get solely the number.
$data = str_replace("</h4>", "", $split_data);
$data = str_replace("TShock servers started in the last 24h:", "", $data);
$data = str_replace("Up to date servers:", "", $data);
$data = str_replace("Port 7777:", "", $data);
$data = str_replace("Online players:", "", $data);
$data = str_replace(" ", "", $data);
// And finally we print out the value.
echo "TShock servers started in the last 24h:<h5>" . $data['1'] . "</h5><br>";
echo "Up to date servers:<h5>" . $data['2'] . "</h5><br>";
echo "Port 7777:<h5>" . $data['3'] . "</h5><br>";
echo "Online players:<h5>" . $data['4'] . "</h5><br>";
// End of file.
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment