How can PHP developers ensure that "#" is correctly displayed in URLs without being converted to "%23"?

When using URLs in PHP, the "#" character is typically reserved for indicating an anchor within a webpage. To ensure that "#" is correctly displayed in URLs without being converted to "%23", developers can use the "rawurlencode()" function to encode the URL component that contains the "#". This function will encode all special characters in the URL component, including "#" which will prevent it from being converted.

$url = 'https://www.example.com/page#section';
$encoded_url = rawurlencode($url);
echo $encoded_url;