What are some best practices for filtering out iFrames from HTML using PHP?

When working with HTML content that may contain iFrames, it is important to filter out these iFrames for security reasons or to control the display of external content. One way to achieve this is by using PHP to parse the HTML content and remove any iFrame tags before displaying it.

<?php
$htmlContent = "<html><body><iframe src='https://example.com'></iframe></body></html>";

// Remove all iFrame tags from the HTML content
$filteredContent = preg_replace('/<iframe.*?>.*?<\/iframe>/is', '', $htmlContent);

echo $filteredContent;
?>