View Full Version : [PHP] Number of habbos online [PHP]
parky1306
16-03-2009, 07:56 PM
Anyone got the code so that i can put it into a PHP file?
I used to use this on my site in the html source
<script src="http://www.habboring.com/online/uk.php" type="text/javascript"></script>
But now HabboRing has shut down, so i cant use that anymore
So i just want to do something similar in html format in my page like the below
<script src="/LINK HERE.php" type="text/javascript"></script>
Any help is appreciated
Edited by ReviewDude (Forum Moderator): Thread closed to prevent further argument, and as the question has been addressed. Moved from "Web Design" as this is coding-related.
Dentafrice
20-03-2009, 01:51 AM
<?php
$hotel = $_GET["hotel"]; // abbrev.. co.uk, com, ca.
$data = @file_get_contents("http://www.habbo.{$hotel}");
if(!$data) {
exit("Could not grab data.");
}
$pattern = '<span class="stats-fig">';
$pattern .= '(\\d+)';
$pattern .= '(<\\/span>)';
preg_match_all ("/{$pattern}/is", $data, $matches);
$habbos = $matches[0][0];
if(empty($habbos)) {
exit("Could not grab data.");
}
echo "There are {$habbos} Habbos online.";
There's the source for how to do it.
Iszak
20-03-2009, 01:58 PM
Caleb: Why match more than you have to? You don't. The regular expression
#<span class="stats-fig">(\d+)</span>#
Does quite nicely and is more effecient than yours. Plus he only wants the habbo's online so you don't need to preg_match_all, in conjunction with yours:
<?php
$hotel = $_GET["hotel"]; // abbrev.. co.uk, com, ca.
$data = @file_get_contents("http://www.habbo.{$_GET["hotel"]}");
if(!$data) {
exit("Could not grab data.");
}
preg_match('#<span class="stats-fig">(\d+)</span>#i', $data, $matches);
$habbos = $matches[1];
if(empty($habbos)) {
exit("Could not grab data.");
}
echo "There are {$habbos} Habbos online.";
Agnostic Bear
20-03-2009, 03:38 PM
why not just use this, seeming as you put all these checks in place but forgot the single most important one: is something actually entered as the url? you might as well just ditch all the checks together.
preg_match( '#<span class="stats-fig">(\d+)</span>#i', @file_get_contents( 'http://habbo.' . $_GET[ 'tld' ] ), $matches );
echo $matches[1];
Protege
20-03-2009, 08:20 PM
omg anova variation!!!
echo ( preg_match( '#<span class="stats-fig">(\d+)</span>#i', @file_get_contents( 'http://habbo.' . $_GET[ 'tld' ] ), $matches ) ) ? end( $matches ) : 'Error' ;
Dentafrice
21-03-2009, 02:39 PM
Caleb: Why match more than you have to? You don't. The regular expression
#<span class="stats-fig">(\d+)</span>#
Does quite nicely and is more effecient than yours. Plus he only wants the habbo's online so you don't need to preg_match_all, in conjunction with yours:
<?php
$hotel = $_GET["hotel"]; // abbrev.. co.uk, com, ca.
$data = @file_get_contents("http://www.habbo.{$_GET["hotel"]}");
if(!$data) {
exit("Could not grab data.");
}
preg_match('#<span class="stats-fig">(\d+)</span>#i', $data, $matches);
$habbos = $matches[1];
if(empty($habbos)) {
exit("Could not grab data.");
}
echo "There are {$habbos} Habbos online.";
I liked how you ****** it up, I was matching the exact same thing you did, except I was splitting it up to see how it was done. (span, integer, span).
You also messed up the abbreviations, since you wanted to be so "smart" and put {$_GET["hotel"]} right along in the string there, you left the $hotel at the top.
Dentafrice
21-03-2009, 04:01 PM
Also Iszak, if you want to argue efficiency, my pattern is quite more efficient with preg_match_all then your pattern is with preg_match.
http://img.skitch.com/20090321-8r2mayrh35m27pe9pm771ybruc.png
Iszak
21-03-2009, 11:51 PM
Yep, mines definitely faster just check the speed of these
http://www.iszak.net/benchmark/bench_iszak.php
http://www.iszak.net/benchmark/bench_caleb.php
and if you think I'm 'rigging' it with the source view it.
http://www.iszak.net/benchmark/bench_iszak.php?highlight=true
http://www.iszak.net/benchmark/bench_caleb.php?highlight=true
The results speak for themselves, you may need to refresh each one to get a more accurate result. Also with mine you don't need the insensitive flag that was accidently added to the code. But I added it to make it fair. Here are some results I got.
Caleb's
1.1262280941
1.12022590637
1.12624311447
1.12477016449
0.972723007202
Mine
0.248840808868
0.249037981033
0.253650903702
0.254599094391
0.252284049988
Cushioned
22-03-2009, 12:01 AM
Yep, mines definitely faster just check the speed of these
http://www.iszak.net/benchmark/bench_iszak.php
http://www.iszak.net/benchmark/bench_caleb.php
and if you think I'm 'rigging' it with the source view it.
http://www.iszak.net/benchmark/bench_iszak.php?highlight=true
http://www.iszak.net/benchmark/bench_caleb.php?highlight=true
The results speak for themselves, you may need to refresh each one to get a more accurate result. Also with mine you don't need the insensitive flag that was accidently added to the code. But I added it to make it fair. Here are some results I got.
Caleb's
1.1262280941
1.12022590637
1.12624311447
1.12477016449
0.972723007202
Mine
0.248840808868
0.249037981033
0.253650903702
0.254599094391
0.252284049988
Mmm... Sweet taste of victory.
BEEYAH!
Blinger1
22-03-2009, 12:08 AM
whats wrong with this way?
<span style="color: rgb(0, 0, 0);"> <span style="color: rgb(0, 0, 187);">
<?php
$hotel = file_get_contents("http://www.habbo.co.uk/");
$start = explode('<span class="stats-fig">', $hotel, 2);
$end = explode('</span>', $start[1], 2);
$habbo = trim($end[0]);
echo("Habbos online: $habbo");
?>
Iszak
22-03-2009, 12:14 AM
There's nothing wrong with that way, I was just proving Caleb wrong that's all.
Blinger1
22-03-2009, 12:18 AM
oh right!!
Well, he sent me a pm (the OP) the other day asking for the code i posted which was an updated version of the one that was posted in the tutorials section.
Dentafrice
22-03-2009, 02:13 PM
We're not doing it 1000 times, or 100 times.. we're doing it one time. And when it comes down to it, my way (one time) if faster then your way.
http://projects.dopaul.com/test.php?name=dentafrice&hotel=co.uk
<?php
$hotel = $_GET["hotel"]; // abbrev.. co.uk, com, ca.
$data = @file_get_contents("http://www.habbo.{$hotel}");
if(!$data) {
exit("Could not grab data.");
}
require_once 'Benchmark/Timer.php';
//create an instance of the Benchmark_Timer class
$timer = new Benchmark_Timer();
//Set "Start" marker
$timer->start();
$pattern = '<span class="stats-fig">';
$pattern .= '(\\d+)';
$pattern .= '(<\\/span>)';
preg_match_all ("/{$pattern}/is", $data, $matches);
$timer->setMarker('caleb');
preg_match('#<span class="stats-fig">(\d+)</span>#i', $data, $matches);
$timer->setMarker('iszak');
//Set "Stop" marker
$timer->stop();
//Returns formatted informations
$timer->display(true);
?>
<br />
<br />
<strong>caleb benchmark code:</strong>
<br />
<code>
$pattern = '<span class="stats-fig">';<br />
$pattern .= '(\\d+)';<br />
$pattern .= '(<\\/span>)';<br />
<br />
preg_match_all ("/{$pattern}/is", $data, $matches);
</code>
<br />
<br />
<strong>iszak benchmark code:</strong><br />
<code>
preg_match('#<span class="stats-fig">(\d+)</span>#i', $data, $matches);
</code>
When it comes to doing it once, my way is faster.
Cushioned
22-03-2009, 07:51 PM
I'm confused as to how yours is faster?
http://www.tehupload.com/uploads/0679644506b19bctemp.PNG
Dentafrice
22-03-2009, 07:55 PM
Refresh more then once.
Source
22-03-2009, 07:56 PM
http://www.tehupload.com/uploads/app-656418760408614645.png
Dentafrice
22-03-2009, 07:59 PM
I'll look at it later, I'm not feeling good/good enough mood to care at the moment.
Source
22-03-2009, 08:01 PM
I was showing yours was faster ^_^
Iszak
22-03-2009, 08:37 PM
Your testing has too many variables Caleb and thus has a less accurate result, check out mine (revised because you said "When it comes to doing it once, my way is faster.") still is faster :)
0.00012993812561 - Caleb
0.0000379085540771 - Mine
Edit: Same links by the way, for those who want to check it out.
Cushioned
22-03-2009, 09:00 PM
Lol. I refresh and yours it faster.
Then I refresh again and his is faster.
And it just goes back and forth again and again. :rolleyes:
tbh, i dont care about which is faster, theyre both pretty fast it makes them near negligible
but anyway:
We're not doing it 1000 times, or 100 times.. we're doing it one time. And when it comes down to it, my way (one time) if faster then your way.
http://projects.dopaul.com/test.php?name=dentafrice&hotel=co.uk
<?php
$hotel = $_GET["hotel"]; // abbrev.. co.uk, com, ca.
$data = @file_get_contents("http://www.habbo.{$hotel}");
if(!$data) {
exit("Could not grab data.");
}
require_once 'Benchmark/Timer.php';
//create an instance of the Benchmark_Timer class
$timer = new Benchmark_Timer();
//Set "Start" marker
$timer->start();
$pattern = '<span class="stats-fig">';
$pattern .= '(\\d+)';
$pattern .= '(<\\/span>)';
preg_match_all ("/{$pattern}/is", $data, $matches);
$timer->setMarker('caleb');
preg_match('#<span class="stats-fig">(\d+)</span>#i', $data, $matches);
$timer->setMarker('iszak');
//Set "Stop" marker
$timer->stop();
//Returns formatted informations
$timer->display(true);
?>
<br />
<br />
<strong>caleb benchmark code:</strong>
<br />
<code>
$pattern = '<span class="stats-fig">';<br />
$pattern .= '(\\d+)';<br />
$pattern .= '(<\\/span>)';<br />
<br />
preg_match_all ("/{$pattern}/is", $data, $matches);
</code>
<br />
<br />
<strong>iszak benchmark code:</strong><br />
<code>
preg_match('#<span class="stats-fig">(\d+)</span>#i', $data, $matches);
</code>
When it comes to doing it once, my way is faster.
Refresh more then once.
You are kinda contradicting yourself here..
Dentafrice
22-03-2009, 09:03 PM
tbh, i dont care about which is faster, theyre both pretty fast it makes them near negligible
but anyway:
You are kinda contradicting yourself here..
Refresh more then once to get a accurate average of times.
That's totally different then doing them in a loop, and recording the time.
Anyways, I'm done here for now.
no but you were saying that youre not going to do it more than once, (which meant that iszak's was faster, but you claimed yours was), but then you said refresh it to get a good average (which makes yours better, when you said iszaks was better)
Protege
22-03-2009, 09:26 PM
oh drama, who gives a **** - they both work and are both reasonably fast.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.