Niet the Dark Absol
Niet the Dark Absol

Reputation: 324640

Sending UTF8 in GET parameter

When navigating to a URL like this:

http://example.com/user?u=ヴィックサ

I notice that Chrome encodes the characters as:

http://example.com/user?u=%E3%83%B4%E3%82%A3%E3%83%83%E3%82%AF%E3%82%B5

And everything works serer-side.

However, in IE I get this error from my code:

The user you are trying to find (?????) does not exist.

Note the five question marks. For some reason the PHP never gets to see the parameter.

What could be causing this, and is there any way to fix it?

Upvotes: 1

Views: 170

Answers (1)

CodeMonkey
CodeMonkey

Reputation: 3331

Sadly it seems what you want to do is not going to work for the current generation of IE

The accepted answer for this question UTF-8 Encoding issue in IE query parameters says that you need to encode the characters yourself rather than relying on the browser as support varies from browser to browser, and maybe even device to device

<a href='/path/to/page/?u=<?=urlencode('ヴィックサ')?>'>View User</a>

Also I presume you are setting utf8 headers from the webserver? you didn't say, if not, in php

header('Content-Type: text/html; charset=utf-8');

Upvotes: 1

Related Questions