What are some best practices for securely including external content in PHP without using iframes?

When including external content in PHP without using iframes, it is important to validate and sanitize the input to prevent any potential security vulnerabilities such as cross-site scripting (XSS) attacks. One way to securely include external content is by using PHP's `file_get_contents()` function to fetch the external content and then output it after sanitizing it with `htmlspecialchars()` to prevent XSS attacks.

$url = 'https://example.com/external-content';
$external_content = file_get_contents($url);
$external_content_sanitized = htmlspecialchars($external_content, ENT_QUOTES, 'UTF-8');

echo $external_content_sanitized;