I am having issues using hebrew with mysql and PHP, i have already tried this:
the db collation has to be utf8_general_ci.
the collation of the table with hebrew has to be utf8_general_ci
in my php connection script i put
header('Content-Type: text/html; charset=utf-8');
in my xhtml head tag i put
after selecting the db in the connection script i put
mysql_query("SET NAMES 'utf8'");
And it is still not working. In phpmyadmin i can see the hebrew characters but when i display them in php all i see is "?????"
If anyone could help me that would be great!
In your html page
Under <head> tage, add <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
At the time of mysql insert use utf8_encode & when show data try to use utf8_decode
Related
I have a little php program which send emails to customers.
The email containes text which is written as html code and also contains data from my MySQL database.
I have tried to change the encoding for the email as UTF-8 and ISO-8859-1.
Depending on the encoding either the html text or the database data is displayed wrong when a word includes special characters.
How do I need to change setting so my emails are displayed correct.
Your question is very limited. I guess your using the code below in your html.
<meta charset="...">
I also guess that your using mysqli to retrieve the data from the database and you not using
mysqli_set_charset()
Here is the Docs for the function above.
I am sorry I did not describe my problem clear enough.
I wanted to send emails through a php file. This email would contain text which is included in the file but also data from a database.
In my php file header I am using
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
In the email header $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
The emails then contains strange symbols for all special letters for parts which are taken from the database.
I have found the following solution which helped me to solve the problem. Just after the database connection it is required to enter the following few lines.
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");
I have mysqldb with some in on series episodes.
But when i fetch this and echo it i get some strange square with a question mark in it.
I want to replace all these to either nothing or something more suitable.
I have googled my ass of and found solution for double quotes but i would like a function that matches all forms of quotes
here is some example
“senior tanning”
�senior tanning�
Mayor’s
Mayor�s
don't know the names of these in English that is why i posting examples :)
I started with php first time yesterday so please be nice :)
When you echo the contents from the database, make sure you have the charset meta tag set to utf-8.
HTML DOCUMENT
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
And in PHP before any output:
header('Content-Type: text/html; charset=utf-8');
And lastly set the MySQL transfer charset:
PDO:
$db->query("SET NAMES utf8");
Or oldschool:
mysql_query("SET NAMES utf8");
and while you're at it, change the MySQL table collation to UTF8_unicode or UTF8_general
You can even add some magic to .htaccess:
AddDefaultCharset utf-8
I've had these charset problems plenty of times, so I know where to find them :)
I have a PHP file encoded with UTF-8 like this :
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
And before using sql request, I've added this line :
mysql_query("SET NAMES 'utf8'");
My database is coded in UTF-8 and varchar column with latin_swedish_ci
The result is like this picture :
Chang code to this
mysql_query("SET NAMES UTF8");
Save file like this
This is due to incorrect collation / charset of your column. Even if your database characted set is UTF-8, the column's character set takes precedence. To handle special characters like japanese chinese you column should be set to utf8_bin instead of latin_swedish_ci
Some Steps to Follow:
Meta tag for UTF8.
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Set your PHP to use UTF8.
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
For MySql, you've to convert your table to UTF8.
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
Also run:
SET NAMES UTF8
as the first query after establishing a connection which will convert your DB connection to UTF8.
html encoding in meta tag gets ignored if it is sent via http headers already.
header('Content-Type: text/html; charset=utf-8');
Check from you browser what it thinks the current page encoding is:
Chrome: Tools - Encoding
Firefox: View - Character encoding
MySQL should be ok with just "set names utf8", table dada is encoded automatically to the mysql connections encoding
I am having a strange issue. I have Swedish characters. My charset works fine when in loop and being pulled from mysql using PHP but when I simply enter HTML text Swedish character Å, Ä and Ö it does not work. Currently this is my set Charset:
<meta http-equiv="content-type" content="text/html" charset="ISO-8859-1">
Here is a picture of how it looks in the browser:
Now here is a picture of data being pulled from Mysql (in loop) on the same page:
If this question has been asked before, please direct me to the page. Could it be somethign to do with the actual page encoding?
You should try this:
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
Probably the file itself ist stored in UTF-8.Try and save it as a ANSI file.
In notepad++ this can be done via Encoding > Encode in ANSI in the menubar.
Or try to change the meta tag as already suggested.
I'm having some trouble with my page. I have moved my site from a host provider to another one, and now i'm having some problems with non-latin characters, for text that comes from db query and for text that is in html/php file.
For text that comes from db someone suggested me to apply this after db connection:
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
and it did the trick, but, now i'm having the same problem for texts that comes from html/php files: instead of ë or ç appears �
I'm sure that should be e trick someone on the server or somewhere else on the configuration.
Hope that you can help me.
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
i'm using at the header of my file.
You must have this line in your <head> section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Is the collation of your database where the data is stored in utf8_general_ci?
Maybe there was a problem while transfering the files.
If you are familiar with Linux, try to fix the broken files on your server with recode
(excerpt: "The Recode library converts files between character sets and usages.")