What are common issues with word censorship in PHP forums and how can they be effectively managed?

One common issue with word censorship in PHP forums is that it may not account for variations of the censored word (e.g., using different characters or spaces). To effectively manage this, you can use regular expressions to match different variations of the word and replace them accordingly.

// List of censored words and their variations
$censoredWords = array('badword', 'b@d w0rd', 'b a d w o r d');

// Input text to censor
$inputText = "This is a b@d w0rd and should be censored.";

// Replace censored words and variations
foreach ($censoredWords as $word) {
    $pattern = '/\b' . preg_quote($word, '/') . '\b/i';
    $replacement = str_repeat('*', strlen($word));
    $inputText = preg_replace($pattern, $replacement, $inputText);
}

echo $inputText;