Are there any potential pitfalls to be aware of when creating links in PHP?

One potential pitfall to be aware of when creating links in PHP is not properly sanitizing user input, which can lead to security vulnerabilities such as cross-site scripting (XSS) attacks. To prevent this, always sanitize any user input used in links before outputting them to the browser.

$link = "<a href='" . htmlspecialchars($user_input_url) . "'>Click here</a>";
echo $link;