I've got a mysql table with some imported data, in particular one value is Sinn Féin.
The character set used for my database is utf8_general_ci. The data displays fine in phpMyAdmin. In my site, I've used the PHP header header("Content-type: text/html; charset='utf-8'");. I've got <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> in my <head>.
My data still comes up as Sinn F�in. I've tried using utf8_decode, but that doesn't help. What am I doing wrong?
Аfter mysql_connect() add this line:
mysql_query ("SET NAMES utf8");
Try this:
$dbc="database connection";
mysql_query("SET NAMES utf8",$dbc);
Related
I have a database which is encoded in UTF8_bin.
Whenever I try to echo something on that database I get questionmarks instead of letters. Anyone knows a solution for that? I think it is important to mention that if I do echo to a word in UTF8 it is just fine. The problem is getting the data from the database.
Please check whether you have followed these steps.
-> db collation must be utf8_general_ci
-> then collation of the table with language has to be utf8_general_ci
-> in your php connection script put header('Content-Type: text/html; charset=utf-8');
-> in xhtml head tag put <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-> after selecting the db in the connection script put mysql_query("SET NAMES 'utf8'");
Then check the connection like this,
if(!mysqli_set_charset($conn, 'utf8')) {
echo 'the connection is not in utf8';
exit();
}
i have a webpage which is based on Smarty 3.3.2 and my webhoster networksolution.com upgraded my php version to the PHP Version 5.4.17-pl0-gentoo and all my arabic characters (database latin1 (tried to utf8 - no results)) are shown like:
®Ù¾Ù„ §Ø±Ù¾®Ù¾Ù„ اØØ؇ ساØ
This is the format like my database inserts but the mainly problem is that before my server was updated (it was 5.2.) it worked correctly, my header is already set up to utf-8
My template is shown correctly, so the problem is with the mysql_query!
Thanks!
First of all please confirm that the arabic text is saving correctly in the database, if it is ok then just add following code just before your select query
mysql_query("set characer set utf8");
and add
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
this code
and if arabic text is not correctly saved in database then please change your database collation to UTF-8.
names are stored in mysql with utf8_unicode_ci.
i get the names from the db with a simple sql request and echo them in a table.
Julián echoes like Julián. Can I run the $name variable through some command to unscramble it, or modify my sql request? it's a simple SELECT name FROM table now.
Check the db connection string, ensure that you have specified the charset utf-8 in your connection string.
And the html encoding charset should also be specified, such as follow:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Tip: Data addition page, check the encoding of the browser. For example if it's Firefox,
Menu -> View -> Character Encoding
Should have been auto detected as Unicode (UTF-8)
execute this query:
"set names 'utf8'" on mysql database
before you execute
"SELECT name FROM table"
It should work! :)
I have the following php code:
<?php
mysql_connect("localhost","root","*****");
mysql_select_db("MyData");
$sql=mysql_query("select * from menu");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
My data base is encoded on utf8_unicode_ci.
So when I read the output in a browser the latin characters a presented well but greek characters are presented with "???????".When I read the data from my data base are presented regularly.
Can someone help me about what do I have to do with my php code?
add these 2 queries to after mysql_select_db("MyData"); :
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
Try
header('Content-type: text/plain;charset=UTF-8');
You'd need to do this before the print() call in your script.
PHP :
header('Content-Type: text/html; charset=utf-8');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
HTML :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
File : Convert file to UTF-8 using notepad
Have a look at your html encoding, because it is likely to be ISO-LATIN-1 default and thus your display is the issue not the sql.
In that case you want to do the following
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head> <?php print(json_encode($output)); ?>
</html>
I solved it in a similar way as MBarsi, adding a line of code after selecting the database, but using mysqli:
$mysqli->select_db("database");
$mysqli->set_charset("utf8");
i have a proble, when insert something in foreign language into database.
i have set the collation of database to utf8_general_ci(try utf8_unicod_ci too).
but when i insert some text into table, it was saved like this
Õ€Õ¡ÕµÕ¥Ö€Õ¥Õ¶ Ô±Õ¶Õ¸Ö‚Õ¶
but when i read from database, text shows in correct form. it looks like that only in database.
i have set encoding in my html document to charset=UTF-8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and i set
mysql_query("SET NAMES UTF-8");
mysql_query("SET CHARACTER SET UTF-8");
when conecting to database.
so i think that i' ve done everything, but it still save in that anknown format.
could you help me.
thanks in advance
I believe you have to SET NAMES utf8, instead of UTF-8, in MySQL.
It looks like maybe your phpmyadmin isn't using the correct charset. In your phpmyadmin folder, open config.default.php and edit the lines
$cfg['DefaultCharset'] = 'iso-8859-1';
$cfg['DefaultLang'] = 'en-iso-8859-1';
To your chosen encoding.
It is suggested to use mysql_set_charset() instead of "SET NAMES" query, however the impact should be the same.