Are there any potential pitfalls in using PHP to manipulate anchors for page reloading?

One potential pitfall in using PHP to manipulate anchors for page reloading is the risk of introducing security vulnerabilities such as cross-site scripting (XSS) attacks if user input is not properly sanitized. To solve this issue, always validate and sanitize user input before using it to manipulate anchors.

// Sanitize user input before using it to manipulate anchors
$anchor = filter_input(INPUT_GET, 'anchor', FILTER_SANITIZE_STRING);

// Output the anchor tag with the sanitized input
echo '<a href="#' . $anchor . '">Reload Page</a>';