Encode UTF-8 for URLs
Posted: Fri May 11, 2012 4:11 am
I know normally one could use rawurlencode() or just urlencode() but alas, these are not working for me.
Basically, I have a string that is UTF-8 encoded with the fancy characters like so:
[text]Gävle[/text]
Now, I need to convert this string to (I don't know the encoding name) look like this:
[text]G%E4vle[/text]
rawurlencode and urlencode both are not encoding the ä at all. How can I do this?
Edit
Just to clarify, it seams that something is working but just not well. For example, I have the string:
[text]Värtavägen 25, Stockholm, Stockholm län, 11553, Sverige[/text]
if I use urlencode() and just print that out to the browser, I get:
[text]V%C3%A4rtav%C3%A4gen+25%2C+Stockholm%2C+Stockholm+l%C3%A4n%2C+11553%2C+Sverige[/text]
which is correct. The problem though is that as soon as I put that into a link, it removes the %C3 type characters (ä) and replaces them with their original ä insanity. I literally have the link:
[text]http://maps.google.se/maps?q=V%C3%A4rta ... -1&iwloc=A[/text]
and as soon as I put this in an address bar, it gets converted to the actual characters which are invalid in a URL. How can I stop this from happening?
Sidenote: I suppose this isn't a PHP question anymore so this post can be moved
Basically, I have a string that is UTF-8 encoded with the fancy characters like so:
[text]Gävle[/text]
Now, I need to convert this string to (I don't know the encoding name) look like this:
[text]G%E4vle[/text]
rawurlencode and urlencode both are not encoding the ä at all. How can I do this?
Edit
Just to clarify, it seams that something is working but just not well. For example, I have the string:
[text]Värtavägen 25, Stockholm, Stockholm län, 11553, Sverige[/text]
if I use urlencode() and just print that out to the browser, I get:
[text]V%C3%A4rtav%C3%A4gen+25%2C+Stockholm%2C+Stockholm+l%C3%A4n%2C+11553%2C+Sverige[/text]
which is correct. The problem though is that as soon as I put that into a link, it removes the %C3 type characters (ä) and replaces them with their original ä insanity. I literally have the link:
[text]http://maps.google.se/maps?q=V%C3%A4rta ... -1&iwloc=A[/text]
and as soon as I put this in an address bar, it gets converted to the actual characters which are invalid in a URL. How can I stop this from happening?
Sidenote: I suppose this isn't a PHP question anymore so this post can be moved