Jump to content

Recommended Posts

line 129- function filterBadWords($str)
{
    $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); 
    $replacements = "*";
    
    while($row = mysql_fetch_assoc($result))
    {     
          $bad_words= $row['badwords'];
          $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words);
          $spaced_bad_words = trim($spaced_bad_words);
          $str = preg_replace("/$bad_words | $spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str);
    }
    
    return $str;
Line 143 - }

 

I go this error "Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in C:\xampp\htdocs\login\chatlog3.php on line 139"

Link to comment
https://forums.phpfreaks.com/topic/253587-preg-replace-error/
Share on other sites

Does $badwords have parentheses in it?

 

 

which parentheses are you saying  this

 

"$spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words);"

 

or

 

"$str = preg_replace("/$bad_words | $spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str);"

 

 

Link to comment
https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300080
Share on other sites

ANY Variable included inside a regular expression MUST be run through preg_quote first.  $badWords obviously has parens in it.

 

Also, why are you doing that preg_replace on spacedBadWords?  What's the goal there?  One space after every letter?  Are you sure that's what you're getting?

Link to comment
https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300175
Share on other sites

ANY Variable included inside a regular expression MUST be run through preg_quote first.  $badWords obviously has parens in it.

 

Also, why are you doing that preg_replace on spacedBadWords?  What's the goal there?  One space after every letter?  Are you sure that's what you're getting?

 

 

actually my first example i had done like this

 

 function filterBadWords($str)
{
    $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); 
    $replacements = "*";
    
    while($row = mysql_fetch_assoc($result))
    {
          $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str);
    }  
    
    return $str;
}

 

 

but the problem is for example i take suck word it can banned  capital letter or small letter of suck but when s u c k(white space included) the word still there

 

 

and im had done example using

 

<?php
function filterBadWords($str) {
    
    $replacements = "*";
    $bad_words_array = array("chit","poop","shat","chits");
    
    foreach($bad_words_array as $bad_words) {
    $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words);
    $spaced_bad_words = trim($spaced_bad_words);
    
          $str = preg_replace("/$bad_words|$spaced_bad_words/i", str_repeat('*', strlen($bad_words)), $str);
    }  
    
    return $str;
}

$text = "I have to deal with a whole pile of chit dealing with you. Even C H I T will work too.";
echo filterBadWords($text);
?>

 

 

and the output is  I have to deal with a whole pile of ****dealing with you. Even **** will work too. but the works that ones is using foreach and array as for me im using database and while statement and im trying to matching but could not get it :( this is my problem :(

Link to comment
https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300179
Share on other sites

Yes...

 

When you do "echo $bad_words" what do you get?

 

 

i got this error :

 

fucksuckassbastardf u c kbitchbuttdickcockgayjerklesbianpenispussysexshitsh!tsluttitvaginab!+chb!tchbi+chmasturbateshi+sh!+boobtesticlebreastpornp0rncoak:)

Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in C:\xampp\htdocs\login\chatlog3.php on line 140

aasetanhisihatfukkacakwtftestis

 

 

 

this is my database

 

23ljlmw.jpg

Link to comment
https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300183
Share on other sites

 function filterBadWords($str)
{
    $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error());
    $replacements = "*";
    
    while($row = mysql_fetch_assoc($result))
    {     
          $bad_words_array = array($row['badwords']);
          $spaced_bad_words = preg_replace("/(.)/i", "\${1} ", $bad_words_array);
          $spaced_bad_words = trim($spaced_bad_words);
          $str = preg_replace("/$bad_words_array|$spaced_bad_words/i", str_repeat('*', strlen($bad_words_array)), $str);
    }

    return  $str;
}


This is the new one that im try to recode surprisely the code works only the problem is the word cannot fillter ;(  Iam don know why it cannot filter 

Link to comment
https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300543
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.