Note that there are some explanatory texts on larger screens.

plurals
  1. POGet non-UTF-8-form fields as UTF-8 in PHP?
    text
    copied!<p>I have a form served in non-UTF-8 (it’s actually in Windows-1251). People, of course, post there any characters they like to. The browser helpfully converts the unpresentable-in-Windows-1251 characters to html entities so I can still recognise them. For example, if user types an →, I receive an <code>&amp;#8594;</code>. That’s partially great, like, if I just echo it back, the browser will correctly display the → no matter what.</p> <p>The problem is, I actually do a htmlspecialchars () on the text before displaying it (it’s a PHP function to convert special characters to HTML entities, e.g. &amp; becomes <code>&amp;amp;</code>). My users sometimes type things like <code>&amp;mdash;</code> or <code>&amp;copy;</code>, and I want to display them as actual <code>&amp;mdash;</code> or <code>&amp;copy;</code>, not — and ©.</p> <p>There’s no way for me to distinguish an → from <code>&amp;#8594;</code>, because I get them both as <code>&amp;#8594;</code>. And, since I htmlspecialchars () the text, <em>and</em> I also get a <code>&amp;#8594;</code> for a → from browser, I echo back an <code>&amp;amp;#8594;</code> which gets displayed as <code>&amp;#8594;</code> in a browser. So the user’s input gets corrupted.</p> <p>Is there a way to say: “Okay, I serve this form in Windows-1251, but will <em>you</em> please just send me the input in UTF-8 and let me deal with it myself”?</p> <p>Oh, I know that the good idea is to switch the whole software to UTF-8, but that is just too much work, and I would be happy to get a quick fix for this. If this matters, the form’s enctype is "multipart/form-data" (includes file uploader, so cannot use any other enctype). I use Apache and PHP. </p> <p>Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload