Skip to content Skip to sidebar Skip to footer

Php Form Submit Utf8?

In my website there is a form with a simple textarea for people to post comments. The problem is that sometimes I receive info in uft8 and sometimes in iso. Is it possible to contr

Solution 1:

If you want to be sure of what character set you are accepting, set it in your form

<formmethod="post"action="/your/url/"accept-charset="UTF-8"></form>

You can see all the acceptable character sets here: Character Sets

Solution 2:

you can always force UTF-8. Then you can send, receive, and store data in UTF-8 ad cover most human languages without having to change character set.

<metahttp-equiv="Content-type"content="text/html; charset=utf-8"/>

Solution 3:

but ... check before encoding, if string is already utf8 else you double-encode it

functionstr_to_utf8 ($string) { 

    if (mb_detect_encoding($string, 'UTF-8', true) === false) { 
      $string = utf8_encode($string); 
    } 

    return$str; 
}

or use

$string = utf8_encode(utf8_decode($string)); 

so you do not double-encode a string

Solution 4:

I solved this problem by changing mbstring.http_input = pass in my php.ini file

Solution 5:

Have you testes with multiple different browsers if the proble occurs on all/some of them or only IE?

Post a Comment for "Php Form Submit Utf8?"