What potential pitfalls should be considered when outputting URLs in PHP?

When outputting URLs in PHP, it is important to properly encode the URLs to prevent any potential security vulnerabilities such as cross-site scripting (XSS) attacks. This can be done using the `urlencode()` function to encode special characters in the URL.

$url = "https://example.com/page.php?param=" . urlencode($user_input);
echo $url;