Recently I worked in a project in where I need to display japanese text which are come from database. I already use
meta http-equiv="Content-Type" content="text/html; charset=utf-8"
It help to display the static text. But when it come from database it display "??????????" type text.
How can I solve this kind of problem?
Is the database charset UTF8 too? Is the connection charset UTF8? Seems like the data gets converted to ISO-8859-1 somewhere along the way.
Without more information, it is hard to find exactly what the problem is. What DBMS are you using? MySQL? PostgreSQL? Either way, I'm pretty sure either your database and/or your connection isn't using UTF8.
You can change your connection charset by using one of the following functions:
mysql_set_charset('UTF-8');
pg_set_client_encoding('UTF-8');
Related
I have a few textfiles which are input for a MySQL database. These textfiles contain characters like é and ë. I have struggled getting the data properly into the database and now it seems I've finally got it right. However, I would like to know if there is a better way to do this than the way I describe here.
The textfiles are all UTF-8 encoded.
The PHP scripts are all UTF-8 encoded as well. I've read that this is very important.
All HTML output is done using a header like this: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The MySQL database is created using a collation of latin1_swedish_ci (the character set is left blank)
All the columns that contain characters (VARCHAR) are defined using a collation of latin1_swedish_ci
I assume the right way to store url encoded strings is when I see the character é stored as %C3%A9 in the database. I found a MySQL function for urlencoding here.
But when I open up phpMyAdmin I see the character é is presented as %C3%A3%C2%A9.
I can add another statement to replace characters in the database, but something tells me there is a more efficient way to achieve this.
Any help is greatly appreciated. Thanks in advance.
What is missing from your list of 5 things is
I tell mysql that the client bytes are utf8-encoded. I do this via $mysqli_obj->set_charset('utf8'); or new PDO('dblib:host=host;dbname=db;charset=UTF8', $user, $pwd); or SET NAMES utf8. (or utf8mb4).
The client sees utf8, the table sees latin1; the conversion will occur when INSERTing and SELECTing, but it needs #6 to know to do so.
Well I have created a page in Dreamweaver where I use phpMyAdmin as a database.
My page can read Swedish letters which are written in Dreamweaver without any problems but when it retrieves data from the database (phpMyAdmin), it gets wrong. Instead of the Swedish letters it says �.
I have encoded with utf- 8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Also the file is saved as utf-8 and I'm using Google Chrome which uses utf 8.
I've heard that I have to encode the connection with the database with utf-8 also, but I don't know how to do that?
As far as I know the way I connect is by:
<?php require_once('Connections/Audiologiska.php'); ?>
Grateful for answers!
Don't forget set charset after connecting to db php mysql charset. Also check if columns has right charset.
On the connection file/class normally i put:
SET NAMES utf8;
And for the database collation i choose utf8_general_ci
Whenever I put ñ in a mysql row... it $_POST's it as a strange triangular ? symbol...
Anyone know what the problem is?
First thing is to check if your mysql column is has the correct encoding (utf8 probably).
Then you may need to enable utf8 when connecting to mysql, at least that's what I must do in Perl.
This link might help http://dreweyscorner.blogspot.com/2008/01/enable-utf-8-on-php-mysql-and-apache.html
It's a mismatch between the encoding used to store the accented character in the database and the charset used by the page that displays it. The text was probably stored as ISO-8859-1 (Western European), but is being displayed as Unicode (UTF-8).
Make sure that the insert form and the display page both use the same encoding. These days, both should have the following tag in the of the page:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Unless you're using an obsolete version of MySQL (such as 3.23), it should support UTF-8 encoding by default.
I have turkish character problem in mysql database when adding content with tinymce from admin panel.
Charset is:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9"" />
How can I solve this?
Thanks in advance
Make sure the table in MySQL is also defined as having charset ISO-8859-9.
There's not enough information to say what your problem is, but in general you need the same character set in your HTML page (text/html;charset), PHP's connection to the database (mysql_set_charset), and MySQL's CREATE TABLE ... DEFAULT CHARACTER SET (if you just CREATE TABLE it will end up in Latin-1 which you probably don't want. Plus you would need to make sure not to use htmlentities-without-charset-argument on output (use htmlspecialchars instead).
See eg. this answer for more detail. That's talking about using UTF-8 for the encoding, but the same applies if you substitute ISO-8859-9 all the way through. (Although unless there's a good reason not to, you should really be using UTF-8.)
well I had a similar problem with my turkish site.
My tables were in latin5_turkish_ci an the charset of the php page were latin5
there was no problem when I submitted the content via php to database, all characters were being saved correctly
but when I tried to submit the content via jquery post method then any turkish character was being saved correctly to database
and php iconv function solved my problem
Our website was developed with a meta tag set to...
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
This works fine for M-dashes and special quotes, etc. However, I have an issue when data has been entered into a CMS component that stores data in MySQL. The MySQL collation is set to UTF8_swedish_ci (I read this is ok and must have been a default when it was set up in phpMySqlAdmin).
The problem I now get is when I output info from the DB to the page, the characters are
utf8 encoded, so I run them through the uft8_decode() php function. I thought this would fix the incompatibility, but what I'm getting isn't what I expect.
When I look at the data in the DB in a text field (again through phpMySqlAdmin) it looks like this...
This – That
When I view it on the screen it looks like...
This ? That
I know I can try to find/replace a bunch of these in the DB or the text, but I'm hoping there's an easier way to do this programatically.
Thanks,
Don
Update:
Still have an issue that htmlentities() unfortunately doesn't fix.
I have text in a file like this: we’ve (special '). My MySQL collation is "latin1_swedish_ci" (the default). If I change the header or meta to either iso/utf one or the other breaks. W/ utf-8 the (’) a black diamond but the db content is fine. With iso, the inline content is ok, but the content from the db has all kinds of  and other chars. Tried changing MySQL collation to utf-8 but didn't see a difference.
I'm about resolved to changing the items manually. Thanks for any other suggestions.
If your data in the database is UTF8, you'll need to run this query after you connect to MySQL:
SET NAMES UTF8
Assuming that you were able to set the encoding properly in your database, my recommended approach here is to:
Make sure that the Content-Type header has been set properly by the
server. This can be done in php by using the header function.
header('Content-Type: text/html; charset=iso-8859-1');
Note that this takes precedence and is the easiest information to get since user agents do not have to parse it.
Set the meta tag in the HTML file.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
For further readings, refer to:
http://www.joelonsoftware.com/articles/Unicode.html
http://www.webstandards.org/learn/articles/askw3c/dec2002/
My guess would be that despite you meta tag, the web server sends a header which sets the charset to UTF-8. However, the easiest way to fix these kinds of problems is usually to escape non-ASCII-characters to HTML entities.