What are some potential pitfalls when manipulating URL strings in PHP?

One potential pitfall when manipulating URL strings in PHP is not properly encoding or decoding special characters. This can lead to errors or unexpected behavior when working with URLs. To avoid this issue, always use functions like urlencode() and urldecode() to safely handle special characters in URL strings.

// Example of properly encoding and decoding URL strings
$url = "https://www.example.com/page?name=John Doe";
$encodedUrl = urlencode($url);
$decodedUrl = urldecode($encodedUrl);

echo $decodedUrl;