What are the best practices for handling HTML and PHP tags in PHP functions like strip_tags()?

When using PHP functions like strip_tags() to remove HTML and PHP tags from a string, it is important to be aware of the potential security risks associated with allowing certain tags to remain in the output. To mitigate these risks, it is recommended to specify a list of allowed tags when using strip_tags() to ensure that only safe tags are preserved in the output.

// Example of using strip_tags() with a list of allowed tags
$allowed_tags = '<b><i><u>';
$clean_string = strip_tags($input_string, $allowed_tags);
echo $clean_string;