What potential issues can arise when dynamically changing the src attribute of an iframe using PHP?

When dynamically changing the src attribute of an iframe using PHP, a potential issue that can arise is the possibility of XSS (cross-site scripting) attacks if the src attribute is not properly sanitized. To solve this issue, it is important to validate and sanitize any user input before dynamically setting it as the src attribute of the iframe.

// Example of sanitizing user input before setting it as the src attribute of an iframe
$src = filter_input(INPUT_GET, 'src', FILTER_SANITIZE_URL);
?>
<iframe src="<?php echo $src; ?>"></iframe>