What are the best practices for handling HTML tags in content previews generated by WYSIWYG editors in PHP?

When generating content previews from WYSIWYG editors in PHP, it's important to handle HTML tags properly to prevent any potential security vulnerabilities or display issues. One common approach is to use PHP's strip_tags() function to remove any unwanted HTML tags while allowing only certain safe tags to be displayed in the preview.

// Get content from WYSIWYG editor
$content = $_POST['content'];

// Strip all HTML tags except for <b> and <i>
$allowed_tags = '<b><i>';
$preview_content = strip_tags($content, $allowed_tags);

// Display the content preview
echo $preview_content;