What are the potential pitfalls of passing anchors in the URL in PHP?

Passing anchors in the URL in PHP can lead to security vulnerabilities such as XSS attacks or injection attacks if the anchor value is not properly sanitized. To prevent this, always sanitize and validate any user input before using it in the URL. This can be done by using functions like htmlspecialchars() to escape special characters.

// Sanitize and validate anchor value before using it in the URL
$anchor = htmlspecialchars($_GET['anchor']);