What best practices should be followed when modifying a script to include a word censor function for user-generated content?

When modifying a script to include a word censor function for user-generated content, it is important to create an array of banned words and then use PHP functions like str_ireplace to replace those words with a placeholder like "***". This helps maintain a clean and respectful environment for all users.

<?php
// Array of banned words
$banned_words = array("badword1", "badword2", "badword3");

// User-generated content
$user_content = "This is a badword1 example of badword2 user-generated badword3 content.";

// Replace banned words with ***
$censored_content = str_ireplace($banned_words, "***", $user_content);

// Output censored content
echo $censored_content;
?>