How can PHP functions like str_replace be utilized to manipulate URLs and improve user experience on a website?

Issue: URLs on a website may contain unwanted characters or parameters that can affect the user experience. By using PHP functions like str_replace, we can manipulate URLs to remove or replace these unwanted elements, resulting in cleaner and more user-friendly URLs.

// Example of using str_replace to manipulate URLs
$url = "https://www.example.com/page?param1=value1&param2=value2";

// Remove unwanted parameters from the URL
$clean_url = str_replace(array('param1=value1', 'param2=value2'), '', $url);

echo $clean_url;