What are best practices for constructing and handling URLs with anchors in PHP header redirection?

When constructing URLs with anchors in PHP header redirection, it is important to properly encode the anchor part of the URL to ensure it is correctly interpreted by the browser. This can be done using the `urlencode()` function in PHP. Additionally, when redirecting with anchors, make sure to include the anchor part in the URL using the `#` symbol.

$anchor = '#section1';
$encodedAnchor = urlencode($anchor);
header("Location: http://example.com/page.php" . $encodedAnchor);
exit();