I have URLs in this format :
http://site.com/index.php?title=%5BSOME_UNICODE_TITLE%5D&id=%5BID%5D&type=%5BTYPE%5D
When I try to use htmlspecialchars on this URL to encode unicode title the function encodes & too; so it will be & so variable name id is converted to ampid !
So I can’t read it from code.
How can I use htmlspecialchars on a URL without converting URL specific chars (e.g. &,=,…)?
IMHO you should just use
urlencode()for URLs, because that’s what it is made for. If you cannot / do not want to use it and you always get a full URI. You could parse if before encoding it:http://php.net/manual/en/function.parse-str.php
http://www.php.net/manual/en/function.parse-url.php
Example: http://codepad.viper-7.com/lIFiHB