What are some best practices for handling and sanitizing external HTML content in PHP applications?

When dealing with external HTML content in PHP applications, it is important to sanitize the input to prevent Cross-Site Scripting (XSS) attacks. One way to do this is by using the `strip_tags()` function to remove any HTML tags from the content. Additionally, you can use the `htmlspecialchars()` function to convert special characters to HTML entities, further protecting against XSS attacks.

// Sanitize external HTML content
$externalContent = "<p>This is <script>alert('malicious script')</script> external content</p>";
$cleanContent = strip_tags($externalContent); // Remove HTML tags
$cleanContent = htmlspecialchars($cleanContent); // Convert special characters to HTML entities

echo $cleanContent;