Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 data received by php isn't decoded

I'm having some troubles with my $_POST/$_REQUEST datas, they appear to be utf8_encoded still.

I am sending conventional ajax post requests, in these conditions:

  • oXhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
  • js file saved under utf8-nobom format
  • meta-tags in html <header> tag setup
  • php files saved under utf-8-nobom format as well
  • encodeURIComponent is used but I tried without and it gives the same result

Ok, so everything is fine: the database is also in utf8, and receives it this way, pages show well.

But when I'm receiving the character "º" for example (through $_REQUEST or $_POST), its binary represention is 11000010 10111010, while "º" hardcoded in php (utf8...) binary representation is 10111010 only.

wtf? I just don't know whether it is a good thing or not... for instance if I use "#º#" as a delimiter of the explode php function, it won't get detected and this is actually the problem which lead me here.

Any help will be as usual greatly appreciated, thank you so much for your time. Best rgds.

EDIT1: checking against mb_check_encoding

if (mb_check_encoding($_REQUEST[$i], 'UTF-8')) {
    raise("$_REQUEST is encoded properly in utf8 at index " . $i);
} else {
    raise(false);
}

The encoding got confirmed, I had the message raised up properly.

like image 814
Sebas Avatar asked Dec 12 '25 20:12

Sebas


1 Answers

Single byte utf-8 characters do not have bit 7(the eight bit) set so 10111010 is not utf-8, your file is probably encoded in ISO-8859-1.

like image 153
Musa Avatar answered Dec 14 '25 10:12

Musa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!