This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Problem + Solution to swear words not working
#1

So, After a week or so of skinning/modifying commentics, I thought I was all done. However, at the last minute, I decided to test the swear words feature (this will be a site for kids), and realized it wasn't working at all!!!

I was about to tear my hair out, but I decided to look into it instead Smile

I don't know why, but for some reason I had to delete some extra space after each word. I tried to figure out what exact letter it was appending to each word (didn't seem to be a blank space exactly), so I just stripped out the last character.

Now it works perfectly for me. Maybe I am the only one that had this problem.

Here is the code I ended up using (almost the same for the mild words).
If anyone had this problem feel free to use:

PHP Code:
<?php 
$comment
= "hi! put some curse words that are in your text file here please!!!!!";
$comment .= "Then save this as whatever.php in the same folder as your swear words and run it to test";
$strong_swear_words_file = "strong_swear_words.txt"; //build path to strong swear words file
if (filesize($strong_swear_words_file) != 0) { //if file is not empty
$strong_swear_words = file($strong_swear_words_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// NEW!!!!!!!!!!!!!!!!!!!!!!!!!!!
$words_array=array();
foreach (
$strong_swear_words as $strong_swear_word) { //for each strong swear word
$new_word=substr($strong_swear_word, 0, -1);
array_push($words_array, $new_word);
}
foreach (
$words_array as $strong_swear_word) {
$strong_swear_word = preg_quote($strong_swear_word, '/'); //escape any special characters
$regexp = "/\b$strong_swear_word\b/i"; //strong swear word pattern (b = word boundary, i = case-insensitive)
$regexp = "/$strong_swear_word/i"; //strong swear word pattern (b = word boundary, i = case-insensitive)

if (preg_match($regexp,$comment)) { //if there is a match
$strong_swear_word_found = true; //set flag as true
echo($strong_swear_word."FOUND!!!!!!!!!!!!!!!>>>>>>><BR>");
}else{
echo(
$strong_swear_word." nope<br>");
}

if ( (
$strong_swear_words_action == "mask" || $strong_swear_words_action == "mask_approve") && (!isset($_POST['preview']) && !isset($_POST['preview_it'])) ) { //if entering a strong swear word should result in masking and not in preview mode
$comment = preg_replace($regexp, $swear_word_masking, $comment); //mask strong swear words
}

}
//end of for-each-strong-swear-word

}

-Pete
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)