SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    in_array question

    I have a small problem. I am checking to see if a username contains a rude word. I just realized that in_array, though, will only check if it is the exact word.
    For example:
    PHP Code:
    if (in_array($username$illegalwords))
    {
        echo 
    "There was at least one disallowed word found in your username.";
        echo 
    "<a href=register.html>Please try again.</a>";
        exit;

    Say the array contained the word "poopyhead"
    Would block it if $username was poopyhead, but if it was youareapoopyhead, it would pass.
    How would I detect this?

  2. #2
    SitePoint Evangelist jplush76's Avatar
    Join Date
    Nov 2003
    Location
    Los Angeles, CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look up the strstr() function
    it will detect if the string name exists anywhere
    My-Bic - Easiest AJAX/PHP Framework Around
    Now Debug PHP scripts with Firebug!

  3. #3
    SitePoint Enthusiast jpp's Avatar
    Join Date
    Nov 2003
    Location
    Arnhem, The Netherlands
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this maybe:

    PHP Code:
    foreach ($illegalwords as $illegalword) {
    if (
    strpos ($illegalword$username))
    {
    //illegal word found
    }




Bookmarks

Posting Permissions

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