Why might it be necessary to use mb_convert_encoding with HTML-ENTITIES encoding when working with URLs in PHP?

When working with URLs in PHP, special characters such as ampersands (&) can cause issues if not properly encoded. Using mb_convert_encoding with HTML-ENTITIES encoding ensures that these special characters are converted to their corresponding HTML entities, allowing the URL to be safely used without causing any parsing errors.

$url = "https://example.com/?param1=value1&param2=value2";
$encoded_url = mb_convert_encoding($url, 'HTML-ENTITIES', 'UTF-8');
echo $encoded_url;