urlencode is useful when using certain URL shortener services.
The returned URL from the shortener may be truncated if not encoded. Ensure the URL is encoded before passing it to a shortener.
Example
$url = "https://www.notarealurl.com?id=50&name=namestring";
$encodedurl = urlencode($url);
$shorturl = UrlShortener::shortenUrl( $encodedurl);