shebbycs Posted December 21, 2011 Share Posted December 21, 2011 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" Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/ Share on other sites More sharing options...
scootstah Posted December 21, 2011 Share Posted December 21, 2011 Does $badwords have parentheses in it? Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300006 Share on other sites More sharing options...
shebbycs Posted December 21, 2011 Author Share Posted December 21, 2011 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);" Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300080 Share on other sites More sharing options...
scootstah Posted December 21, 2011 Share Posted December 21, 2011 I'm talking about the value of $bad_words. Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300102 Share on other sites More sharing options...
shebbycs Posted December 21, 2011 Author Share Posted December 21, 2011 I'm talking about the value of $bad_words. $bad_words= $row['badwords']; you means this one? Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300137 Share on other sites More sharing options...
scootstah Posted December 21, 2011 Share Posted December 21, 2011 Yes... When you do "echo $bad_words" what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300141 Share on other sites More sharing options...
ManiacDan Posted December 21, 2011 Share Posted December 21, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300175 Share on other sites More sharing options...
shebbycs Posted December 21, 2011 Author Share Posted December 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300179 Share on other sites More sharing options...
shebbycs Posted December 21, 2011 Author Share Posted December 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300183 Share on other sites More sharing options...
shebbycs Posted December 22, 2011 Author Share Posted December 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253587-preg-replace-error/#findComment-1300543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.