What are the potential pitfalls of using iframes in PHP for including external content?

Potential pitfalls of using iframes in PHP for including external content include security risks such as cross-site scripting attacks, performance issues due to additional HTTP requests, and limited control over the styling and behavior of the included content. To mitigate these risks, consider using PHP's file_get_contents() function to fetch external content server-side and then sanitize and display it within your PHP script.

<?php
// Fetch external content using file_get_contents()
$external_content = file_get_contents('https://example.com/external-content');

// Sanitize the external content
$external_content = htmlspecialchars($external_content);

// Display the sanitized external content
echo $external_content;
?>