Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php form submit utf8?

Tags:

html

php

encoding

In my website there is a form with a simple textarea for people to post comments. The problem is that sometimes I receive information in UTF-8 and sometimes in ISO. Is it possible to control that?

Maybe I am doing something wrong, but is it possible that the browser changes the codification of the data it sends?

like image 951
Raul Leaño Martinet Avatar asked Feb 04 '11 19:02

Raul Leaño Martinet


1 Answers

But... check before encoding, if string is already UTF-8. Else you double-encode it.

function str_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.

like image 181
3 revs, 2 users 94% Avatar answered Nov 06 '22 19:11

3 revs, 2 users 94%