Jump to content


Help with wildcard and regular expressions.. Urgent..

  • Please log in to reply
No replies to this topic

#1 maggotondlus

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 26 April 2006 - 08:39 AM

Hi everyone... Please help me on this one...

I just finished a script that will check if a string or an array of strings contains offensive/swear words.

Now my problem is how can I match a string containing spaces (i.e S H I T) with the bad word saved in my database (i.e shit)?

I am having trouble with this. Can anyone help me please.. Thanks!

Here's the function that I did:

function swear_checker($sc_string) {
    if (!is_array($sc_string)) return "Error: Data not an array";
    $query = "SELECT   table.swear_checker.sc_word
                FROM     table.swear_checker
                ORDER BY table.swear_checker.sc_id";
    $result = mysql_query($query) or die(mysql_error());
    $rl = mysql_num_rows($result);
    foreach ($sc_string as $key => $value) {
        $arrayVal[] = $value;
    while ($rs = mysql_fetch_array($result)) {
        foreach( $arrayVal as $key => $value) {
            $match = ereg_replace($rs[sc_word], "****", $value);
            if ($match != $value) {
                return false;
            } else {
                $string = $sc_string;
    return true;

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users