What are the best practices for embedding links within iframes in PHP to ensure proper functionality?

When embedding links within iframes in PHP, it is important to ensure that the URLs are properly formatted to avoid any issues with functionality. One common practice is to use the `urlencode()` function to encode the URLs before embedding them within the iframe. This helps to ensure that any special characters in the URL are properly encoded and do not cause any problems when the iframe is loaded.

$url = 'https://example.com/page?param1=value1&param2=value2';
$encoded_url = urlencode($url);

echo '<iframe src="' . $encoded_url . '"></iframe>';