How can the urlencode and urldecode functions be used to properly display Google referrers in PHP?

When displaying Google referrers in PHP, the referrer URL may contain special characters that need to be properly encoded and decoded using urlencode and urldecode functions. This ensures that the URL is correctly displayed and processed by the PHP script.

// Get the referrer URL
$referrer = $_SERVER['HTTP_REFERER'];

// Encode the referrer URL
$encoded_referrer = urlencode($referrer);

// Decode the encoded referrer URL
$decoded_referrer = urldecode($encoded_referrer);

// Display the decoded referrer URL
echo $decoded_referrer;