Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Join Date
    Feb 2007
    Location
    UK
    Posts
    56
    Tokens
    0

    Default [PHP] Number of habbos online [PHP]

    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.
    Last edited by ReviewDude; 25-03-2009 at 08:01 AM.

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    PHP Code:
    <?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.

  3. #3

    Default

    Caleb: Why match more than you have to? You don't. The regular expression
    Code:
    #<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 Code:
    <?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.";
    Last edited by Iszak; 20-03-2009 at 02:01 PM. Reason: Sentence structure.

  4. #4
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    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.

    PHP Code:
    preg_match'#<span class="stats-fig">(\d+)</span>#i', @file_get_contents'http://habbo.' $_GET'tld' ] ), $matches );
    echo 
    $matches[1]; 


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  5. #5
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    omg anova variation!!!
    PHP Code:
    echo ( preg_match'#<span class="stats-fig">(\d+)</span>#i', @file_get_contents'http://habbo.' $_GET'tld' ] ), $matches ) ) ? end$matches ) : 'Error' 
    Last edited by Protege; 20-03-2009 at 08:25 PM.
    Hi, names James. I am a web developer.

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Iszak View Post
    Caleb: Why match more than you have to? You don't. The regular expression
    Code:
    #<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 Code:
    <?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.

  7. #7
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    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.


  8. #8

    Default

    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...highlight=true
    http://www.iszak.net/benchmark/bench...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
    Code:
    1.1262280941
    1.12022590637
    1.12624311447
    1.12477016449
    0.972723007202
    Mine
    Code:
    0.248840808868
    0.249037981033
    0.253650903702
    0.254599094391
    0.252284049988

  9. #9
    Join Date
    May 2008
    Posts
    1,160
    Tokens
    11

    Latest Awards:

    Default

    Quote Originally Posted by Iszak View Post
    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...highlight=true
    http://www.iszak.net/benchmark/bench...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
    Code:
    1.1262280941
    1.12022590637
    1.12624311447
    1.12477016449
    0.972723007202
    Mine
    Code:
    0.248840808868
    0.249037981033
    0.253650903702
    0.254599094391
    0.252284049988
    Mmm... Sweet taste of victory.
    BEEYAH!
    Previously a Habbo fanatic, web designer/developer, fansite owner, & trusted member of the community.

  10. #10
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    whats wrong with this way?

    <span style="color: rgb(0, 0, 0);"> <span style="color: rgb(0, 0, 187);">
    PHP Code:
    <?php
    $hotel 
    file_get_contents("http://www.habbo.co.uk/");
        
    $start explode('<span class="stats-fig">'$hotel2);
    $end explode('</span>'$start[1], 2);
    $habbo trim($end[0]);

    echo(
    "Habbos online: $habbo");
    ?>

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •