0
votes

folks, I need you help please. I have a form with some inputs that expect some special chars. Thats why I want to use utf-8 encoding. It set it in HTML as a meta-tag, in PHP as a header and directly in the form with "accept-charset". Yet, I get the following:

var_dump($_POST['name']) => "dagã¶bert" (original input: "dägobert")
var_dump(mb_detect_encoding($_POST['vorname'])); => "ascii"

I have absolutely no idea left on what more to do to get this working. I appreciate any hint.

1
So you have set this?, just to be sure Content-Type: text/html;charset=utf-8Destrif
I have set it like this in the HTML-Head <meta charset="utf-8" />cycophyp

1 Answers

-1
votes

To make sure, that your web server output (from php) is interpreted as utf-8, you can set the encoding explicitly by calling:

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

at the beginning of your php script. It is important that this is called before any other output is done by the script, else an error occurs, that headers could not be set any more.

The <meta charset="utf-8"> tag is not sufficient. You should use the meta tag as well to provide the encoding even in the case that a user decides to store the page locally and view it later again (when noch Content-Type is provided any more, because the page doesn't come from the web server any more).