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!


Results 1 to 8 of 8

Thread: PHP Help

  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default PHP Help

    Okay. So lets say theres a website called www.lol.com/index.html and on that website it says:

    Hi. My name is John Doe.

    I use file_get_contents('www.lol.com/index.html'); and specify $lol = file_get_contents('www.lol.com/index.html');

    So now $lol is basically: Hi. My name is John Doe.

    Now I want to get rid of the Hi. My name is and the . (period) at the end so all I have left is John Doe

    How do I do that? Do I use strstr and strrchr? If I do, how do I get the info in between?
    Vouches
    [x][x]

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

    Latest Awards:

    Default

    bruv man

    explode function & str_replace function bruv

    <?php
    $lol = 'Hi. My name is John Doe.'
    $str = explode( ' ', $lol );
    $newString = $str[ 3 ] . ' ' . str_replace( '.', '', $str[ 4 ] );
    echo $newString;
    ?>

    aint tested btw
    Hi, names James. I am a web developer.

  3. #3
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Ah yes. I forgot about explode()

    Thanks and +rep

    Edit: kk all i got was is john

    and btw you forgot the ; on line 2
    Last edited by Trigs; 01-02-2009 at 10:45 PM.
    Vouches
    [x][x]

  4. #4
    Join Date
    Sep 2008
    Posts
    718
    Tokens
    0

    Default

    Quote Originally Posted by Protege View Post
    bruv man

    explode function & str_replace function bruv

    <?php
    $lol = 'Hi. My name is John Doe.'
    $str = explode( ' ', $lol );
    $newString = $str[ 3 ] . ' ' . str_replace( '.', '', $str[ 4 ] );
    echo $newString;
    ?>

    aint tested btw
    Quote Originally Posted by Fazon View Post
    Ah yes. I forgot about explode()

    Thanks and +rep

    Edit: kk all i got was is john

    and btw you forgot the ; on line 2
    Ik close to nothing about PHP, but just try fiddling with the code, for example maybe change the numbers? (No idea what that will do, but you can always change back) Good luck
    +.net - omg it's coming o_o

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

    Latest Awards:

    Default

    Quote Originally Posted by Fazon View Post
    Okay. So lets say theres a website called www.lol.com/index.html and on that website it says:

    Hi. My name is John Doe.

    I use file_get_contents('www.lol.com/index.html'); and specify $lol = file_get_contents('www.lol.com/index.html');

    So now $lol is basically: Hi. My name is John Doe.

    Now I want to get rid of the Hi. My name is and the . (period) at the end so all I have left is John Doe

    How do I do that? Do I use strstr and strrchr? If I do, how do I get the info in between?
    assuming it will always be a 2 word name, use this:

    PHP Code:
    <?php
    $file 
    file_get_contents'filename' );
    $file explode' '$file );
    $c count$file ) - 1;
    $name $file[ ( $c ) ] . ' ' $file$c ];
    $name preg_replace'#\.$#'''$name );
    then use name

    i am not sure but this should work

    edit: it does work i just tried it
    Last edited by Jewish Bear; 02-02-2009 at 12:36 AM.

  6. #6
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    I don't understand one thing from what jewish bear posted...

    Okay well what I want to do is get Chris Paul's PPG, APG, and RPG from http://sports.yahoo.com/nba/players/3930
    Vouches
    [x][x]

  7. #7
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    This code will steal the charts from Radio 1's Charts:

    PHP Code:
    $page file_get_contents("http://www.bbc.co.uk/radio1/chart/singles.shtml");
    $start explode('<!-- CHART TABLE -->'$page2);
    $end explode('<!-- END CHART TABLE -->'$start[1], 2);
    $resulttrim($end[0]);
    echo 
    $result
    If you look in the source of the charts page, you will see they have the following lines:
    <!-- CHART TABLE -->
    <!-- END CHART TABLE -->

    That code will get anything in between them

  8. #8
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,789
    Habbo
    HotelUser

    Latest Awards:

    Default

    Quote Originally Posted by Fazon View Post
    I don't understand one thing from what jewish bear posted...
    If the text "Hi. My name is" never changes use Protege's. If you think the "Hi. My name is" might ever change, use Jewish Bear's.

    If it was me I would have just done this:
    PHP Code:
    <?php
    $lol 
    file_get_contents('www.lol.com/index.html');
    $split explode('Hi. My name is ',$lol);
    $split explode('.',$split[1]);
    $name $split[0];

    echo 
    $name;

    ?>
    I'd do it that way incase there was any additional text or formatting on the page you're getting the source from.
    Last edited by HotelUser; 02-02-2009 at 02:13 AM.
    I'm not crazy, ask my toaster.

Posting Permissions

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