1

I have an issue and I can find a lot of questions about this issue on this board. I would like Polish characters by POST :

When I send with a form by POST the following data:

Ciało wielbłądów osiąga długość do 3 m. Ich szyja jest długa, łukowato wygięta; głowa długa,

PHP displays the following:

<p>Ciało wielbłądów osiąga długość do 3 m. Ich szyja jest długa, łukowato wygięta; głowa długa,

Even when directly doing:

exit(print_r($_POST));

At the top of the page.


What have I done so far?

I tried to use HTML entities

exit(htmlentities($_POST['EditorField'], ENT_NOQUOTES, 'UTF-8'));

I tried to use utf8_decode

exit(utf8_decode($_POST['EditorField']));

I have set the internal encoding at UTF-8 :

mb_internal_encoding('UTF-8');

This takes place very early in the frameworks initialization class. I hope there is something that I have missed and could be working anyway.

Edit:

I added the following :

<form action="" method="post" accept-charset="utf-8">

accept-charset="utf-8"

And I removed the TinyMCE editor

Still no luck!

Ciało wielbłąd&oacute;w osiąga długość do 3 m. Ich szyja jest długa, łukowato wygięta; głowa długa

Edit: In the mean time I did find the following:

Adding:

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

This does the trick for the $_POST to be correctly send. I thought that this was the same as :

mb_internal_encoding('UTF-8');

But I was wrong.

There is a small problem that still occurs though. When saving the data with PDO it still truncates the data.

I my opinion I still use the correct settings to initialize the connection

///########==================================================
///######## SET OPTIONS FOR PDO IN ARRRAY FORMAT        
///########==================================================
$options = array(
                    PDO::ATTR_PERSISTENT                =>      true, 
                    PDO::ATTR_ERRMODE                   =>      PDO::ERRMODE_EXCEPTION,
                    PDO::ATTR_DEFAULT_FETCH_MODE        =>      PDO::FETCH_ASSOC,
                    PDO::MYSQL_ATTR_INIT_COMMAND        =>      'SET NAMES utf8'
                );
///########==================================================



///########==================================================
///######## TRY CONNECTING WITH THE PDO DATABASE
///########==================================================
try {
    ///######## MAKE THE CONNECTION AND ASSIGN IT TO : DBH
    self::$DbConnection[$ConnectionName] = new PDO(
                                                        $dsn,
                                                        self::$DbCredentials[$ConnectionName]['username'],
                                                        self::$DbCredentials[$ConnectionName]['password'],
                                                        $options
                                                    );
    ///######## SET UTF 8
    self::$DbConnection[$ConnectionName]->exec('SET CHARACTER SET utf8');
}
///######## CATCH ANY ERRORS
catch (PDOException $e) {
    ///######## IF ANY ERRORS JUST SHOW THEM
    ///self::$error = $e->getMessage();
    exit(self::errorField('<strong>PDO database connection error</strong><br />'.$e->getMessage()));
}
///########==================================================

(* still I make a mistake somewhere of course. But now I have to find it... *)

Solved!! I hope someone could still up me this post because I found the solution. And it lays in a total different direction than all other noted problems on this board:

Required :

header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');

BUT REMOVED!! :

                        PDO::MYSQL_ATTR_INIT_COMMAND        =>      'SET NAMES utf8'

I also removed :

self::$DbConnection[$ConnectionName]->exec('SET CHARACTER SET utf8');

Tried both of the mentioned above individually. But now it works.

Alex
  • 1,223
  • 1
  • 19
  • 31
  • What does you form / input box look like? the posted results look to have a encoded

    tag at start, do you have any type of JavaScript formatting running on the input field that could be adding this?

    – Re0sless Sep 29 '15 at 08:39
  • I use a TinyMCE Editor. Good point BTW!! – Alex Sep 29 '15 at 08:57
  • I would try removing TinyMCE for now to see if its that that messing it up, you could also try adding `accept-charset="utf-8"` to your form tag if it is not already there. – Re0sless Sep 29 '15 at 09:08
  • Tried both. (* after your comment ;-) *) unfortunately no luck. – Alex Sep 29 '15 at 09:35
  • Is the file itself (both, the one with the form, and the other one that is processing it) saved in UTF-8? `mb_internal_econding` or `meta charset` might not help if the file itself is not saved with the same encoding. – ROAL Sep 29 '15 at 10:03
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Sep 29 '15 at 10:10

0 Answers0