What are the best practices for handling URL display manipulation in PHP to ensure optimal user experience?

When displaying URLs in PHP, it's important to ensure they are user-friendly and easy to read. One common practice is to use clean, descriptive URLs that are easy for users to understand and remember. Additionally, it's important to properly encode URLs to prevent any errors or security vulnerabilities.

// Example of handling URL display manipulation in PHP

$url = "https://www.example.com/page.php?id=123&name=John+Doe";

// Clean and user-friendly URL display
$cleanUrl = "https://www.example.com/profile/123/john-doe";

// Encoding URLs to prevent errors or vulnerabilities
$encodedUrl = urlencode($url);

echo "Clean URL: " . $cleanUrl . "<br>";
echo "Encoded URL: " . $encodedUrl;