I have a mysql database with latin1 default character set name.
Through php I save strings in mysql table. From the table I parse some data into tables using DataTables.
Everything work ok, but now I have some problems with circumflex letters and FPDF.
So if I save a string "račun" in the table, the result in the table will be "raÄun".
Or the string "število" will be "Å¡tevilo".
OK -> DataTables decodes those words back normally..
But now when I am using FPDF it gets those string as they are stored in MySQL table and print them "encoded".
I tried
iconv("ISO-8859-1", "ISO-8859-2", "Števika računa")
and
utf8_decode("Števika računa)
But nothing worked.. does anybody has an idea what should I do?
At the end this was the solution:
http://isabelcastillo.com/international-characters-encoding-fpdf
Related
I have problem with encoding while trying to import data from CSV file to MySQL database in PhpStorm. The CSV file contains Cyrillic symbols. I've read some articles, tried many things, but none of them worked for me.
In my.ini file I changed:
collation_server=utf8_unicode_ci to collation_server=utf8mb4_unicode_ci and
character_set_server=utf8 to character_set_server=utf8mb4
but the result was still the same.
That's my CSV file:
NAME_1,NAME_2,NAME_3
Vladimir,Ivanov,Kaziyski
ИВАН,ПЕТРОВ,ГЕОРГИЕВ
John,Lee,Smith
ПЕТЪР,ЙОРДАНОВ,ПЕТРОВ
In PhpStorm I click right-button on the database which I will import data and then I click:
then I chose the CSV file
and in the Data Preview section everything looks normal, encoding is set to UTF-8
and after that I get this error
Here is the log:
2:1: Data truncation: Incorrect string value: '\xD0\x98\xD0\x92\xD0\x90...' for column `current_db`.`csv_data`.`NAME_1` at row 2
3:1: Data truncation: Incorrect string value: '\xD0\x98\xD0\x92\xD0\x90...' for column `current_db`.`csv_data`.`NAME_1` at row 1
4:1: Data truncation: Incorrect string value: '\xD0\x98\xD0\x92\xD0\x90...' for column `current_db`.`csv_data`.`NAME_1` at row 2
5:1: Data truncation: Incorrect string value: '\xD0\x9F\xD0\x95\xD0\xA2...' for column `current_db`.`csv_data`.`NAME_1` at row 1
I've searched this error and tried almost all solutions, but nothing worked. The problem for sure is Cyrillic. Does anyone with PhpStorm had the same issue and how to fix it?
utf8 vs utf8mb4 does not matter for Cyrillic, only for Emoji and Chinese.
Please provide SHOW CREATE TABLE. I suspect you did not change the CHARACTER SET for the column(s) that will receive the Cyrillic characters.
I have a site developed in codeigniter where I'd like to insert a record inside my database in a table with utf8 fields.
The problem is that when I insert something inside the table I see that:
�"�h�t�t�p�:�/�/�I�m�a�g�e�1�.�u�r�l�f�o�r�i�m�a�g�e�s�.�c�o�m�/�D�e�f�a�u�l�t�/�8�8�0�4�/�2�3�6�9�2�2�6�2�-�1�8�4�3�3�8�5�2�6�6�.�j�p�g�"�
There are many more characters. The real string is a simple path. I don't know the format of the string because it is from an external server.
This is my query to insert record. I take the string from xml and if I print it inside the page I see the correct string. The problem occurs whenever I check inside the database:
foreach($img->childNodes as $node){
$data = array(
'image'=>$node->getAttribute('path'),
);
$this->db->insert('hotel_images',$data);
}
That data is not UTF-8. It is UCS-2 or UTF-16. UCS-2 is a subset of UTF-16, so treating it as UTF-16 should do the trick.
You can convert it using iconv.
$data = iconv("UTF-16", "UTF-8", $data);
I am trying to save a string in database and get something like this
Период д

The string that I want to save : Период действия S...
The table encoding is: cp1251_general_ci
I don't know in which encoding the string is - I am getting it from an excel document.
I tried this, but it didn' help.
$nomer = iconv('UTF-8','Windows-1251', $str );
Is there a solution for this?
You haven't mentioned the database engine you're using, but try changing the table encoding to something like utf8_general_ci or utf8_unicode_ci.
I tried to insert Hebrew a text value into a column,
But it changes the value to Gibberish.
An example of that:
mssql_query ("UPDATE TABLE SET COLUMON = N'בדיקה'");
As you can assume, It changes the value of the column, But the value changed to ????? and if I try to do it from Query Analyser it works fine.
My column's collation is HEBREW_CI_AS. How can I fix this?
You need to specify collation preperty for the string in the INSERT statement you are using. Also the string you are inserting should be of UNICODE datatype - use N prefix for that.
INSERT INTO MEMB_INFO (User, Pass, Name) VALUES ('Joni', '123456', N'גוני דף' COLLATE HEBREW_CI_AS)
Check that PHP variable can handle unicode characters. Otherwise it will be PHP that turns your string into question marks.
You may check out SQL Server drivers for PHP.
And Unicode Character Properties from PHP doicumentation.
Some resources on PHP and unicode:
http://www.sitepoint.com/bringing-unicode-to-php-with-portable-utf8/
http://php.net/manual/en/function.utf8-encode.php
http://allseeing-i.com/How-to-setup-your-PHP-site-to-use-UTF8
http://www.yiiframework.com/wiki/16/how-to-set-up-unicode/
http://pageconfig.com/post/portable-utf8
I solve this problem if someone else has this problem here is my way to fix that:
Create a new database for this specific table or else tables for your web.
Set Hebrew_CI_AS as collation (everyone to what he created).
In your PHP code use mb_convert_encoding() function for SELECT and INSERT.
I'm currently using this function to obfuscate a bit the field values in MySQL and protect it from direct dumping. It all works good and values are stored correctly, but what happens when i try to store a multibyte string?
Here's an example, let's try to encode the string álex:
<?
$v = xorencode('álex');
// step 1 - encode
echo $v."\n";
// step 2 - decode
echo xorencode($v);
?>
Works good, i see some obfuscated string first time, and then i see álex again. Now if i try to save it in a VARCHAR field in a MySQL table, and then select it - i no longer have a utf string, instead it gets returned as gllex.
Note, MySQL tables and fields collations are utf8_general_ci, files are UTF-8, and i SET NAMES utf8 after connecting. Any workaround to this?
Thanks