1

I have a PHP script to publish articles. It was working perfectly fine until we added the file uploading support. To enable uploading of files, we had to change enctype of tag to multipart/form-data. Now, whenever we try to submit an article with multibyte characters, they become garbled after you receive them via $_POST. If we remove the form's enctype, then it works fine.

We have searched for all over the web for a php centric solution but without luck. There is an accept-charset attribute of tag but it does not work in IE. There is a solution for JSP at UTF-8 text is garbled when form is posted as multipart/form-data but no solution for PHP. So, please help!

Community
  • 1
  • 1
  • Actually, this sentence makes you sound a bit insane: *"We have searched for all over the web"* given the size of the web, you are likely not ready with it and thinking you could tell us you did makes you sounding a bit crazy. – hakre Apr 18 '13 at 13:23
  • And the solution is independent to PHP or JSP or whatever. You first of all need to understand how character encodings and HTML work: [W3C Internationalization: Introducing Character Sets and Encodings](http://www.w3.org/International/getting-started/characters) – hakre Apr 18 '13 at 13:26
  • you need to set the encoding of the html page containing the form. Browsers use this encoding to send the GET/POST data. – Bass Jobsen Apr 18 '13 at 18:49
  • @bass-jobsen, thanks for your message. I can confirm that the encoding of html page that contains the form is set to UTF-8. – Ajay Chadha Apr 19 '13 at 13:58
  • @hakre, the sentence "we have searched all over the web" was not meant to take out literal meaning out of it. It was just meant to convey a message that we have searched and didn't found any solution on web. Please correct me if I am wrong there is any solution out there. We tried various tips available online without any luck. – Ajay Chadha Apr 19 '13 at 14:02
  • 1
    Please provide the schema how you process data with its metadata and the collaborators. That should make visible where the encoding chain is broken. – hakre Apr 19 '13 at 14:25
  • you refer to the jsp solution in php you can use: `mb_detect_encoding` and `utf8_encode` something like `mb_detect_encoding($_POST['field']) != 'UTF-8') $_POST['field'] = utf8_encode($_POST['field']);` – Bass Jobsen Apr 19 '13 at 14:38
  • Amazing but I have encountered at this problem in 2023 year! The symptoms are exactly the same. I am using newest php7.4 and of course WIN (11). And the question is how I can developing on windows with correct encoding behaviour? – Marek G. Apr 25 '23 at 20:09

2 Answers2

2

if you use PHP 5.4.x, setting mbstring.http_input from "auto" to "pass" may solve your problem.

she hates me
  • 1,212
  • 5
  • 25
  • 44
0

Reinstalling apache and recompile php fixed it for some ppl on linux.

I had the same on my localhost, but on the production server this does not happen. My local is WAMP, production is LAMP, everything has the same version.

So to me it works with these: CentOs 6.3, php 5.4, Apache 2.2.15

Btw, on my local, mb_detect_encoding() showes 'UTF-8' but the string is mess anyway.

Skacc
  • 1,726
  • 2
  • 12
  • 16