HabboxWiki needs you!
Are you a Habbo buff? Or maybe a rare trader with a bunch of LTDs? Get involved with HabboxWiki to share your knowledge!
Join our team!
Whether you're raving for rares, excited for events or happy helping, there's something for you! Click here to apply
Need a helping hand?
Check out our guides for all things to help you make friends, make rooms, and make money!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default [Tut] Creating a World Filter and Smily Parser

    In this tutorial im going to show you how to create a basic Word filter and smiley Parser. Its Split in to 4 parts. The first 2 parts are about the word filter, firstly its code and secondly a breakdown of the code.
    The 3rd and 4th part follow the same patten except on the topic Smilys parsing.

    I hope this is helpful to some people.

    Word Filtering
    First off we want to create are filter function. In the case of the example i will be using healthy foods instead of swear words.

    PHP Code:
    function filter($msg)
    {
    $bad_words explode(','"tomato,lettuce,carrot,potato,broccoli,cucumber,pea" );
      foreach (
    $bad_words as $naughty)
       {
      
    $msg eregi_replace($naughty"****"$msg);
       }
    return 
    $msg

    Now to filter those words you just run apply the function to the input
    PHP Code:
    $input "Hello i am a carrot salesman made of lettuce";
    $output filter($input);
    echo 
    $output;
    //This would then print out, "Hello i am a **** salesman made of ****" 
    Word Filtering Breakdown
    Ok now lets look at how the word filtering works.

    PHP Code:
    function filter($msg)

    We set up the function
    PHP Code:
    $bad_words explode(','"tomato,lettuce,carrot,potato,broccoli,cucumber,pea" ); 
    Now we create an array of all are bad words. The array in the example is "tomato,lettuce,carrot,potato,broccoli,cucumber,pe a" Change this to your needs, simply seperate every word with a comma.
    PHP Code:
    foreach ($bad_words as $naughty)
       {
      
    $msg eregi_replace($naughty"****"$msg);
       } 
    Now we loop threw the array and run an eregi_replace on each, substituting **** for each of the words in the bad words list.
    PHP Code:
    return $msg

    Then We return the filtered variable and end the function.

    Making Smiles
    In this part im gonna quickly go threw how to convert text smiley to there image equivalents.

    PHP Code:
    function doSmily($msg)
    {
    $msg str_replace(':)''<img src="Smileys/smile.gif" alt=":)" />'$msg);
    $msg str_replace(':(''<img src="Smileys/sad.gif" alt=":(" />'$msg);
    $msg str_replace(':D''<img src="Smileys/biggrin.gif" alt=":D" />'$msg);
    $msg str_replace(';)''<img src="Smileys/wink.gif" alt=";)" />'$msg);
    $msg str_replace(':o''<img src="Smileys/ohmy.gif" alt=":o" />'$msg);

    return 
    $msg;

    This can be called in pretty much the same way as the first
    PHP Code:
    $input "Hey there :D how are you all ;)";
    $output doSmily($input);
    echo 
    $output;
    //This would then print out the message complete with image smilys 
    Making Smiles Breakdown
    Now Lets look at how it works.

    PHP Code:
    function doSmily($msg)

    We open the Function
    PHP Code:
    $msg str_replace(':)''<img src="Smileys/smile.gif" alt=":)" />'$msg);
    $msg str_replace(':(''<img src="Smileys/sad.gif" alt=":(" />'$msg);
    $msg str_replace(':D''<img src="Smileys/biggrin.gif" alt=":D" />'$msg);
    $msg str_replace(';)''<img src="Smileys/wink.gif" alt=";)" />'$msg);
    $msg str_replace(':o''<img src="Smileys/ohmy.gif" alt=":o" />'$msg); 
    We use the string replace method to look threw the string and replace any occurrence of the smiley with the relevant image code.

    $msg = str_replace(':)', '<img src="Smileys/smile.gif" alt=":)" />', $msg);

    The first bold part is the smiley. And the second is the image code which is what we replace it with.
    You can easily change this to your requirements.
    PHP Code:
    return $msg;

    Then finally we return the value

    iCrag (Forum Moderator): Good tutorial, moved to Website Tutorials.
    Last edited by the wombats; 05-08-2006 at 01:16 PM.

  2. #2
    Join Date
    Dec 2005
    Posts
    724
    Tokens
    0

    Default

    Very good tut might use the word censor for next security upgrade at europehabbbo
    Starting webdesign again.

  3. #3
    Join Date
    Sep 2005
    Posts
    5,253
    Tokens
    3,625

    Latest Awards:

    Default

    remind me to do that next tme i'm bored and decide i need a decent website

  4. #4
    Join Date
    Aug 2005
    Location
    Location Location
    Posts
    1,730
    Tokens
    0

    Latest Awards:

    Default

    Good tut but web design how?

  5. #5
    Join Date
    Jun 2006
    Location
    Nottinghamshire
    Posts
    184
    Tokens
    0

    Default

    Nice tut. I'll use that in the making of my CMS
    Last edited by The Voice; 05-08-2006 at 10:36 AM.

  6. #6
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    233
    Tokens
    0

    Default

    Quote Originally Posted by Flauvo
    Good tut but web design how?
    Web Design isn't just the design aspect or coding aspect, the category should be named Web Development. Using PHP to do things like this or with XML etc come under that, this would be useful for a custom PHP/ASP forum if you were to re-code it in ASP, but also for a CMS..

    So stop being arrogant and learn how to be constructive.

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

    Latest Awards:

    Default

    Quote Originally Posted by Flauvo
    Good tut but web design how?
    Well most obviously in terms of it being used for Webdesign. if your designing a CMS for a website, filtering bad words or parsing smilys are often an important part. Hence are part of designing that website.

    Next you'l be asking how a webpage layout is webdesign...

  8. #8
    Join Date
    May 2006
    Location
    My House
    Posts
    66
    Tokens
    0

    Default

    Great work and tutorial, well done


  9. #9
    Join Date
    Jun 2006
    Location
    california
    Posts
    384
    Tokens
    0

    Default

    **Removed**

    Edited by Bomb-Head (Forum Moderator): Please don't avoid the filter, thanks
    Last edited by Bomb-Head; 10-02-2007 at 05:08 PM.

  10. #10
    Join Date
    Aug 2006
    Posts
    28
    Tokens
    0

    Default

    Quote Originally Posted by frozen
    **Text removed from quote**
    You see these hatin' wiggas, I got mode between the furniz, they bump and they gone. How we go low, dont do that. GANGSTA, don't Callie know? Tell her now, before she pops up. We go spit it limb from limb, you know the crones got it, we ridin' till 25. You talkin bull, you motha ya bruv and ya dog, gangsta gangsta im a ****g rider.

    ** U MAN.
    Last edited by Bomb-Head; 10-02-2007 at 05:09 PM.
    Ima rider.

Page 1 of 2 12 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
  •