Cannot get certain characters imported into MySQL [duplicate] - php

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
This issue is absolutely killing me, I cannot get a single solution online to work!
I am trying to import the following text from a CSV to a MySQL table - via Navicat's import wizard:
L154 – TRAINING WARRANTY
The hyphen is a wide hyphen and so far I've managed to import it as either a question mark, or a black diamond with question mark inside. Same for £ symbols and other special characters.
Everyone always talks about UTF-8. So far I have tried:
Saving the CSV in Excel, clicking Tools > Web Options > Encoding: UTF-8
Right clicking the database and clicking EDIT. Setting Char set to utf8 Unicode and Collation: utf8_general_ci
I have "designed" the table and set the 2 options above to exactly the same.
I have edited the varchar field in question and set the same 2 fields again to the 2 types above.
But my hyphen will not import correctly.
It would be nice to know exactly how to go about importing data that has £ symbols and other special characters once and for all.

You can use htmlentities() to store these symbols in encoded form like e.g.
£ will be £ and – will be –, by using:
echo htmlentities('£');
and when retrieving, just use html_entity_decode() Like:
echo html_entity_decode('£'); // output £
Edit: As discussed in the comments, how you are trying to import the data from a CSV file. You have to change the encoding for the CSV file, which can be done using Notepad++, By going to Encoding->Encode in UTF-8

Related

Write/retrieve special characters ⓄⒼקร to Database [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 6 years ago.
I have a form that needs to accept special font characters and write them to the database table. I believe the encoding is set correctly at the page/form level but when the field is written to the database the characters get changed to some other encoding. Other SO answers seem to indicate setting encoding to UTF-8 is the answer, which i've done.
Now, if I copy paste the characters below, direct to the database table, it holds them just fine as shown. Its only when I write it to the table from the form or when i retrieve it for display in web page.
Example characters: ⓄⒼקร
The web page is set as: <meta charset="utf-8">
The form tag includes attribute: accept-charset="UTF-8"
Php just before the INSERT has: $_POST['tag']=utf8_encode($_POST['tag']);
I have not had to write/encode those types of font/special characters before, so what am i doing wrong here?
Do not use the PHP utf8_encode() or utf8_decode() functions.
Despite their promising-sounding names, what these functions actually do is mangle UTF8 text -- either by double-encoding UTF8 text, or by converting text to the ISO8859-1 encoding and replacing characters outside the Latin-1 range with question marks.
Remove the call to utf8_encode(), make sure your database table has the proper encoding (CHARACTER SET = utf8mb4), and you should be fine.

Converting characters from MySQL Database to standard characters [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 7 years ago.
I have a database which contains some blocks of text. These text blocks contain extended characters such as: ’ ‘ … “ and ”. When displayed directly to a web page they all show like this: �.
I've tried doing as str_replace to show normal characters, with no luck.
I've tried iconv, which will only work when set to ignore, which makes the punctuation look wrong.
I've tried html_encode, which also doesn't work. (I'm also using the parsedown script to format the text.)
The funny thing is, the website I'm replacing supports these characters fine, so I don't know what I'm doing wrong! (I don't have access to this website, or source code, or database, which is why I'm replacing it!)
Can anyone provide any help??
I just want to stop showing � and start showing proper characters!
Thanks to the above linked article, this issue is now resolved.
I firstly changed the collation of all of my tables as follows:
Specify the utf8mb4 character set on all tables and text columns in
your database.
Then in my php code where it connects to the database, I added this line:
$CONNECTION -> set_charset('utf8mb4');
All issues resolved! Thanks to all who contributed to my fix!

Russian utf-8 shows special characters? (PHP) [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I displayed some Russian words on HTML and it showed like following.
Полный кадр
The result is:
Полный кадр
I tried to convert the original string to UTF8 and displayed in HTML. I showed like above.
Some information:
store field collation: latin1_swedish_ci
The sql result is :
ÐолнÑй кадÑ
I queried the database and get the value. And then convert to utf8:
mb_convert_encoding($value, 'utf-8', 'windows-1251');
Could you please take a look at this link. Someone fixed it:
http://stackoverflow.com/questions/13765242/need-help-determining-encoding-of-the-text
The problem is I'm rebuilding a website. Some data is from old website. And I cannot input it manually because It's a lot. So I wrote a php script to get data from the old website and inserted to my new website. The old website display russian in HTML perfectly. But I didn't code it, and I cannot see his code.
I already check the data between old table and new table. It's the same.
You should change collation for your table to e.g. utf8_unicode_ci, or koir... for Russian, so you can get the right result. latin_swedish does not support Cyrillic characters.

php search function not displaying the correct encoding [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I'm building a php search page for a photo gallery to pull data with Chinese characters from MySQL.
I've done the following:
1. setting webpage to utf-8 encoding meta http-equiv="content-type" content="text/html";charset="utf-8"
2. ensure that the collation for mysql db and data itself is utf8_general_ci
3. set chrome encoding to utf-8.
But when I put in a positive search string to pull data with Chinese characters, they always come up as ???
I've checked my php array raw output and it is also ??? which leads me to believe there is something wrong at my database end. But I need to add is my gallery page (where the search box is embedded) displays the Chinese characters correctly from the same database.
Have you also set $mysqli->set_charset('utf8'); ?

Character encoding for music symbols in mySQL [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
I am trying to store the characters ♯ and ♭ in a mySQL database, but ♯ gets stored as A♯ and ♭ as Bâ™
In the HTML, I have used ♯ and ♯ and both render fine in the browser, but neither is being stored correctly.
I have tried UTF-8 and UTF-16 character sets for both the PHP page and for the field where the values are being stored and I get the same result.
I'm not very familiar with character sets, so maybe I should be using something other that UTF-8 or -16 or maybe I'm missing something else entirely?
did you try to use varbinary / binary.
If you have again the problem, check your DB charset, table charset, col charset, php script charset.
If you have the problem after, you can use base64_(en|de)code :)

Categories