Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post

    Exclamation Help with regular expression

    Can't seem to get this to work.

    I have an array or words which have to be filtered out.

    Now for each word it can only be filtered if there is a space or a non-word character at the start and at the end.

    I had a go at it but nothing good came out of it. heh,.

    Oh also the variable name is $bw so it'd be like (\040|\W($bw)\040|\W) or something?
    Omnis mico antequam dominus Spookster!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm warning you, I know nothing about reg exp's. Using my book a bit of common sense I cam up with the following script:

    PHP Code:
    <?php

    $badwords 
    = Array();
    $badwords[] = "hate";
    $badwords[] = "suck";

    $usrinput "Hello, my name is Joe. I hate regular expressions. They suck. Testhate , will it replace that <-- ? I hope not! Regular exp's suck, they really do.";

    foreach ( 
    $badwords as $bg ) {
      
    $usrinput ereg_replace("[^a-zA-Z0-9]".$bg."[^a-zA-Z0-9]""xxx"$usrinput);
    }

    print 
    $usrinput;

    ?>
    Only problem is that it matches and replaces the non-alphanumeric character before and after the found expressions. I don't know how to make it so it checks for something, but doesn't replace it. Hopefully it is something you can try to work with.

    It's not that I trully dislike regular expressions, it's that I don't have a good understanding of them and human nature dictates that we are afraid/show hatred towards that which we do not know, or know little about. ( ignorance == "fear" )
    Last edited by x_goose_x; 04-12-2003 at 08:57 AM.

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks x_goose_x! You're a champ.
    Omnis mico antequam dominus Spookster!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't thank me, thank the cheapest book I could find, "SAMS teach yours..."

  • #5
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    lol, might get that book. hrmm..
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

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