Difference Firefox - Chrome when encoding umlauts

Chrome converts this: aöüß to %C3%A4%C3%B6%C3%BC%C3%9F But Firefox converts it to this strange thing: a%F6%FC%DF It seems I can’t find a way to convert the Firefox thing to the original in PHP. Unfortunately, Urldecode and rawurldecode do not work. Does anyone know how to deal with this? Thanks.

+6
source share
2 answers

As Tay already suggested: Chrome uses UTF-8 (as probably recommended) for URL parameters, while Firefox uses Latin-1. I do not think you can control this behavior. It will also be difficult to handle, because you need to guess the encoding used.

This is how decoding works (it depends on the browser if you use UTF-8 in your application):

Chrome:

 $text = urldecode($_GET['text']); 

Firefox:

 $text = utf8_encode(urldecode($_GET['text'])); 

This may be a solution that works in most cases:

 function urldecode_utf8($text) { $decoded = urldecode($text); if (!mb_check_encoding($decoded, 'UTF-8')) { $decoded = utf8_encode($decoded); } return $decoded; } 
+5
source

Make your page use UTF-8. These codes are likely to differ in coded umlauts. One of them is similar to Latin1, and the other is similar to UTF-8.

The best way to force utf-8 is in the html meta tag.

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
+1
source

Source: https://habr.com/ru/post/912226/


All Articles