Page 1 of 1

Encode UTF-8 for URLs

Posted: Fri May 11, 2012 4:11 am
by shiznatix
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

Re: Encode UTF-8 for URLs

Posted: Fri May 11, 2012 1:27 pm
by tr0gd0rr
Google maps is using the "iso-8859-1" as the charset. If you change it to "ie=utf-8" google properly displays the location.

Re: Encode UTF-8 for URLs

Posted: Mon May 14, 2012 1:42 am
by shiznatix
tr0gd0rr wrote:Google maps is using the "iso-8859-1" as the charset. If you change it to "ie=utf-8" google properly displays the location.
Ha, I had no idea. Thanks a million