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 4 1234 LastLast
Results 1 to 10 of 31
  1. #1
    Join Date
    Aug 2005
    Posts
    856
    Tokens
    0

    Default [PHP] How do I...

    Oki, this will take some explaining.

    I have the code:
    PHP Code:
    :ban xRoyal15 
    Now, :ban is the function, xRoyal15 is the username.

    I want to extract the username from that code, and use it.

    So, someone types
    PHP Code:
    :ban xRoyal15 
    It extracts the username (xRoyal15) from that shout, and ban it.

    How would I go about extracting the username from the code?

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Well first you would need to set up somthing to match the :ban so the function first activates, then you can use preg replace to remove the ":ban " bit and be left with the use name, you could then hash that to an id, and do what ever you like "/

    preg_match plus preg_replace usin kinda stuff... very vaige and random i know, but im lazy, if you want a more detailed exsplination just tell me, and if i have time ill actulay provide more helful info on the sort of code... if your already good with php, and it was just a conceptal prob, hopefuly my vage crap will have helped anyway

  3. #3
    Join Date
    Aug 2005
    Posts
    856
    Tokens
    0

    Default

    Yer, im good with php, but i still sorta confused.

    Good you go into more detail, maybe show me an example :rolleyes:

  4. #4
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    How much of the shout box do you have working so far?

    Basicly every time someone says somthing, you wana look at the code for adding that to the DB.

    Then you want to use preg_match in an if statment around it.
    aka *persudo code*
    if preg_match finds the text "ban:" in the input

    Do the ban stuff here, aka preg_replace the text "ban: " and get the username.
    Then useing the usename, updated the mysql to ether set somthing in there account to banned, or add there ip to a blocked list or somthing

    Else (if its not ban)

    Normal code to add new shout here

    end if

  5. #5
    Join Date
    Aug 2005
    Posts
    856
    Tokens
    0

    Default

    It all works so far, so what you mean is...

    PHP Code:
    if(preg_match == :ban){
    preg_replace(:ban)
    }else{
    STUFF


  6. #6
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    693
    Tokens
    0

    Default

    Tried and tested way:
    PHP Code:
    <?php
    $ban 
    ":ban xRoyal15";
    echo 
    $ban;
    $ban explode(" "$ban);
    $ban['0'] = "";
    $ban implode(""$ban);
    echo 
    "<br />$ban"//In quotes so I can use <br />
    ?>
    I guess you're not as good with php as I first thought. ;>
    Last edited by Heinous; 09-11-2006 at 11:05 PM.
    XHTML, CSS, AJAX, JS, php, MySQL.

    --

    HxF moderators can't read timestamps.

  7. #7
    Join Date
    Aug 2005
    Posts
    856
    Tokens
    0

    Default

    Ah no... what happens is...

    Shoutbox > Admin types :Ban x (x being user) > preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x > bans x

    So i need this bit preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x >

    and i can do the rest

    On the shoutbox:

    $name = $logged[username];
    $shout = $_POST[shout];
    Last edited by xRoyal15; 09-11-2006 at 11:10 PM.

  8. #8
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    693
    Tokens
    0

    Default

    Quote Originally Posted by xRoyal15 View Post
    Ah no... what happens is...

    Shoutbox > Admin types :Ban x (x being user) > preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x > bans x

    So i need this bit preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x >

    and i can do the rest

    On the shoutbox:

    $name = $logged[username];
    $shout = $_POST[shout];
    Do you wanna make yourself clearer? I just gave you something that gives the username from a string, what do you want exactly?

    edit:
    oh wait, gotcha, code in a minute.
    Last edited by Heinous; 09-11-2006 at 11:12 PM.
    XHTML, CSS, AJAX, JS, php, MySQL.

    --

    HxF moderators can't read timestamps.

  9. #9
    Join Date
    Aug 2005
    Posts
    856
    Tokens
    0

    Default

    1. User posts shout ($shout)
    2. If($logged[level] == 12){
    3. Does a preg_match to find if it has :ban in it
    4. If it does, it removes the ban, to give the username
    5. username can then be used to ban the user
    6. }else{
    7. Inserts into database as a post


    Clear as i can be

    Edit: Just seen ya edit, oki
    Last edited by xRoyal15; 09-11-2006 at 11:15 PM.

  10. #10
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    693
    Tokens
    0

    Default

    PHP Code:
    <?php
    if ($logged[level] == 12)
        {
            
    $shout ":ban xRoyal15"//Assume this is $_POST[shout]
            
    if (stristr($shout":ban"))
                {
                    
    $ban explode(" "$ban);
                    
    $ban['0'] = "";
                    
    $ban implode(""$ban);
                    
    //Function or whatever to ban the user here.
                
    }
        }
    ?>
    stristr > preg_match

    (preg_match returns an array)

    That *should* work.
    XHTML, CSS, AJAX, JS, php, MySQL.

    --

    HxF moderators can't read timestamps.

Page 1 of 4 1234 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
  •