2

I am developing a service and you can send different parameter to this service via the get parameter.

For example:

www.example.com?query=john&location=...

It is also possible to send umlauts to this service.

Ex.

www.example.com?query=müller

My problem now is, that i have no influence of how parameters are sent to my service, so i've decided to test it a lot and discovered, that if you try to call it via our internally system (which runs with Sharepoint) and if you use Internet Explorer, things start getting weird. First of all, those parameter look something like this, with the second example above:

www.example.com?query=m�ller

I can already detect, if someone's using IE, but i'm still not sure, how I can fix this problem.

I already tried to use urlencode() (and a lot of other functions, but they don't really change the result), which returns m%3Fller. My desired output in this case would be m%C3%BCller

Is it somehow possible to solve this with my service or is the problem in Sharepoint? I've already reproduced the szenario with a simple HTML form with all the required parameters as simple text fields and it works fine there.

EDIT:

My desired output is the umlaut in the correct form for a url (ü => %C3%BC)

PrototypeX7
  • 154
  • 2
  • 10
  • 1
    The question is, where does it look like that? Depending on where it is displayed you should look if the output is really UTF-8 / unicode instead of iso-8859-1 (latin1) or some kind. Also, depending on your browser (version) it could be send in non-unicode – Ronald Swets Apr 14 '16 at 12:07
  • 1
    It's already sent to my browser like this, which means, i never really get the `müller`, i only get this � instead of the ü – PrototypeX7 Apr 14 '16 at 12:14
  • Are you declaring anything regarding charsets/encodings anywhere in your HTTP response or page, or are you just leaving it up to the browser to decide? (You may have guessed that the latter isn't very productive.) – deceze Apr 14 '16 at 12:15
  • Just added `header('Content-Type: text/html; charset=utf-8');` to my code, but it doesn't really change something – PrototypeX7 Apr 14 '16 at 12:18
  • Does it perhaps now fail equally across all browsers with that header? – deceze Apr 14 '16 at 12:50
  • I cannot say more, than it has to do with the way how IE sends URLs: https://blogs.msdn.microsoft.com/ieinternals/2014/04/22/unicode-in-url-changes-for-ie11/ – Bernhard Döbler Sep 27 '18 at 08:05

3 Answers3

2

Put this code on one of the first lines of you PHP code:

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

It changes the charset to utf-8 which supports the Ü.

You can also use htmlentities to change the Ü to üuuml; but if you don't want that you can also just use urlencode which returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

Source:
http://php.net/manual/en/function.htmlentities.php
http://php.net/manual/en/function.urlencode.php

Tom
  • 606
  • 7
  • 28
  • Did this now, but it doesn't really change the result. As already mentioned above in my question, i have no influence of how letters are sent to my service. `urlencode` returns something better than the �, but it is not what i want. Actually i just have to send this parameter to another website (also with get parameter), but it should be in the right format, which is (in my case) `%C3%BC` for the `ü` – PrototypeX7 Apr 14 '16 at 12:28
1

does it pass trough a form? If so, for me this solved the problem, just add the accept-charset="UTF-8" to the form

George
  • 111
  • 1
  • 7
0

It depends on your page encoding, I would suggest if it's possible to change it to UTF-8, then example like this:

<?php
$txt = "müller";
$output = urlencode($txt);
var_dump($output);

Will return you proper value:

string(11) "m%C3%BCller"
Tomasz
  • 4,847
  • 2
  • 32
  • 41