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&oacute;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ó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.
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