What are the potential security risks of using iframes to display PHP-generated content in HTML files?

Using iframes to display PHP-generated content in HTML files can pose security risks such as cross-site scripting (XSS) attacks, where malicious scripts can be injected into the iframe content and executed in the context of the parent page. To mitigate this risk, it is recommended to sanitize and validate the PHP-generated content before displaying it in the iframe.

<?php
// Sanitize and validate PHP-generated content
$php_content = "<p>This is the PHP-generated content</p>";
$php_content = htmlspecialchars($php_content);
?>
<iframe srcdoc="<?php echo $php_content; ?>"></iframe>