I am using UTF-8 in my HTML and have set my database table's collation to UTF-8 Unicode. The data I am saving comes from an external source, but when viewing it on the website (in UTF-8) it works out fine.
Now when I store the values from php using an insert query, values like 'Bearwölf' misform to 'Bearwölf'.
How do I get around this? I don't think there's many more details to provide, if you think of something please let me know.
Changed the API to give utf 8 encoded strings, problem solved.
Related
Is there a way I can store ñ or Ñ characters in my postgres database, database is SQL_ASCII...
What I do is insert for "ñ" and in the database it saves as "ñ", output still "ñ" and that's good. But what I want is to insert "ñ" in the database as is.
My problem is some applications output the "ñ", like ateila or Crystal reports.
Any ideas guys?
Convert it to UTF-8 and give it a go, it should work.
Check this question for more info:
SQL_ASCII is generally a bad idea. Consider converting your database to UTF-8. It's hard to do because your DB will be full of badly encoded data, but it will save you a lot of pain down the track.
SQL_ASCII DBs can store non-ASCII chars just fine. Your applications just have to all expect the same encoding, and always consistently convert to/from that encoding. client_encoding is ignored. In your application you must always make sure to convert text you get from external sources into that encoding, and convert data from the DB into the encoding expected by the external recipient. The main thing with SQL_ASCII is that the DB won't check to make sure you're doing it right. It won't convert for you and it won't verify that the data matches client_encoding. There's no metadata to tell clients what encoding you're using.
Change to UTF-8.
I'm having a problem parsing data from different feeds, some of them in English, others in Italian and others in Spanish. I'm parsing using a PHP script and saving the parsed data into my MySQL database.
The problem is that when I parse items that contains "non common" characters like: "Strage di Viareggio Più" when I look into my database the phrase is stored in this way: "Strage di Viareggio Più".
My database can use that kind character because when I input that manualy it works fine, in the original feed (rss file) the phrase is also fine, I think is my PHP server who is changing the letter. How can I solve this? Thanks!
Make sure that the database uses UTF-8 (as you say it does) and that the PHP script has its internal encoding set to UTF-8, which you can achieve with iconv_set_encoding. If you're reading data from an HTTP request that should be all you need, as long as the request tags its own encoding correctly.
Looks like input data is in UTF-8, but charset/collation of DB table - ASCII. I would suggest to have UTF-8 everywhere.
What you need to implement, before saving to MySQL is:
http://php.net/manual/en/function.htmlentities.php
Check these different threads for more information
Best practices in PHP and MySQL with international strings
htmlentities() makes Chinese characters unusable
What I find incredible is that this question has received -2 in the past 24 hours without any comments.
From the question posted:
I'm parsing using a PHP script and saving the parsed data into my MySQL database.
and
I think is my PHP server who is changing the letter. How can I solve this? Thanks!
The answers posted so far are related to the encoding and settings of MySQL. The person asking the question has clearly stated that he can insert special characters manually and is having no problems:
My database can use that kind character because when I input that manualy it works fine
My answer was to help him convert the characters into an html entity which will circumvent the problem he is having with the RSS feed and answering the question posted.
I have two tables here - one is in UTF and holds Arabic text as it can be read. The other one has a different encoding however and the content is Arabic however in the database its displayed as
ÈöÓúãö Çááøåö ÇáÑøóÍúãóäö ÇáÑøóÍöíãö
I have to show data from both tables on the same page - the page is UTF encoded however I'm not sure if this can be done or if its possible. What do i do? My database is mysql and I'm using php.
Is it possible to convert the encoding of the contents of the other table into UTF8 btw?
You have to use mb_convert_encoding() first, on everything, to make sure it's all in UTF-8 to begin with. http://us3.php.net/manual/en/function.mb-convert-encoding.php Then it should display, assuming your HTML's charset is UTF-8 and the users have the appropriate fonts installed.
Also, virtually all consoles and a great many free online SQL commanders (like PHPMyAdmin) are not UTF-8 aware and print out jibberish. I have not yet found a free SSH client that supports UTF-8; if it's a big deal, invest in SecureCRT.
EDIT:
Excuse me. I don't read Arabic at all, but I did get Arabic back. please tell me if this is the correct text, and if so, accept this answer ;_)
ب?س?ك? افف?م? افر??ح?ك?ل? افر??ح?ٍك?
The code I used to get this was:
header('Content-Type: text/html;charset=utf-8');
echo mb_convert_encoding('ÈöÓúãö Çááøåö ÇáÑøóÍúãóäö ÇáÑøóÍöíãö', 'utf-8', 'iso-8859-6');
I found the Arabic encoding via this page: http://a4esl.org/c/charset.html
Cheers!
I've been looking for a solution to this issue and have tried most answers found. But with no luck was I able to insert the Japanese xml feed into the tables which have been created.
I tried setting all setting where UTF8 should be used as most answers have suggested - But no luck!!
Check that the connection character set is UTF-8 by making it issue SET NAMES utf8 as the first task it does.
Check that the page you are using to view the data is marked as UTF-8: do this either by sending a content-type header that specifies UTF-8, or by adding a meta tag that says so (I'm sorry, I don't know much about XML so I don't know how it is done).
Check that the data you are receiving is encoded as UTF-8. If it is encoded in some other character set but you are presenting it to MySQL as UTF-8, then it may get stored mis-encoded in the database, or MySQL may make the best sense of it that it can and garble/truncate it as a result.
The database has a ton of entries that were not escaped because they were inputted manually when they were inserted so they look like: Don't inside of the entry, but when I try to display them they have a weird characters when I output in PHP. Before I would put anything into the database I would usually use mysqli_real_escape_string and then do the same when I go to retrieve the data, but since the data is already stored without using real_escape how do I display it properly?
The character being displayed instead of the single quotes looks like this: �
If it helps the data is stored as 'text'.
Thanks!
For future users of the same problem here's the steps:
Check your website headers to see what the encoding is
Check your mysql table columns and make sure they match.
If they don't change them to match. utf8_general in mysql and utf8 in my HTML worked for me
You will have to go back through the old mysql tables and update them so the new encoding is set properly.
New entries should work fine
When you output your results in PHP (or I guess whatever language you use), depending on if you are using any validation, you may have to use mysqli_real_escape_string or a similar function, such as stripslashes()
You'll need to read up on text encoding.
The usual solution is to make sure everything (the content-type encoding on your pages, and your mysql) are set to UTF-8
Chances are your data is Latin1 and you're displaying UTF-8 or vise versa