Brackson
卍卍卍卍卍卍卍卍卍卍卍
Hello DevBest.
This is probably one of my first PHP scripts that I actually tried to make and understand, and I was wondering what you guys thought of it and if it could be optimized or not.
What this script does is reads the online count of an index page of a specific retro. I understand that not all retros have their online count in the same div, and I know that this script has to be personalized for every website that you use it on.
Also, please excuse the thread title; it's kind of hard to think of a name for something like this.
Here it is!
Save this as YOUR_FILE.PHP.
and save this file something else.
*Special thanks to Heaplink for these two scripts, which are much more efficient than my first. Compare
I used Xenon because I'm a staff member on it, and it has it's online count on it's index page (which makes it a lot easier). I figured that this script would be good for fansites and such, since it echo's the code as plain text, and you can style it how ever you want to.
What do you guys think?
This has not been released yet. Please do not release this.
This is probably one of my first PHP scripts that I actually tried to make and understand, and I was wondering what you guys thought of it and if it could be optimized or not.
What this script does is reads the online count of an index page of a specific retro. I understand that not all retros have their online count in the same div, and I know that this script has to be personalized for every website that you use it on.
Also, please excuse the thread title; it's kind of hard to think of a name for something like this.
Here it is!
Save this as YOUR_FILE.PHP.
PHP:
<?php
require_once 'simple_html_dom.php';
// Download here http://sourceforge.net/projects/simplehtmldom/files/simple_html_dom.php/download
// It parses the HTML so we can get the div from the source easier than regular expression.
/**
* Gets number of online users
* @return int The number of users online
**/
function getOnlineUsers() {
$url = "http://xenon.pw/?novote";
$html = file_get_html($url);
$onlineUsers = $html->find('div[id="online"]');
return intval(strip_tags($onlineUsers[0]));
}
and save this file something else.
PHP:
<?php
require_once 'YOUR_FILE.php';
?>
<html>
<head>
<title>Better script (by Heaplink)</title
</head>
<body>
<p>There are <b><?=getOnlineUsers() ?></b> users online, irght now!</p>
</body>
</html>
You must be registered for see links
.I used Xenon because I'm a staff member on it, and it has it's online count on it's index page (which makes it a lot easier). I figured that this script would be good for fansites and such, since it echo's the code as plain text, and you can style it how ever you want to.
What do you guys think?
This has not been released yet. Please do not release this.