开发者

The database does not collect the content other than English [Charset/Unicode set to UTF-8]

I have moved my server from dreamhost to Godaddy recently

When I was with Dreamhost it was no problem when my visitors submitting a form in my website using other language than English.

For example they use Thai language when they submit the form I receive it with no problem.

but what happen now when they submit any form I will receive a text like ?????????? so I though it might be just the setting on the php.ini file if that was set correctly and I see it was using UTF-8

; PHP's built-in default is text/html
default_m开发者_如何转开发imetype = "text/html"
default_charset = "UTF-8"

and

exif.encode_unicode = "UTF-8"
exif.decode_unicode_motorola = "UCS-2BE"
exif.decode_unicode_intel = "UCS-2LE"
;exif.encode_jis = 
exif.decode_jis_motorola = JIS
exif.decode_jis_intel = JIS

but I can't figure out why this is happen while all was set correctly

and each of my html/php header file I have included

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

Any suggestion what I missed?


To put some more information that

If I use the FTP client such as Filezilla there will be another problem that when I edit the file .php or .html the content in the file if it has any other language than English it will go all like question mark ??????? but if I edit it from the web like Net2ftp then it has no problem on that


I had a similar problem with PHP + MySQL, MySQL refused to properly store UTF8 strings. The solution was to tell MySQL each time after connection, to use UTF8. I believe the SQL command to do so was SET CHARACTER SET UTF8, or SET NAMES UTF8 but I'm not sure, it was a long ago.

Edit: Found some old PHP code of mine, I hope it is helpful:

function sql_connect(){

global $host,$user,$pass,$dbname,$conn;

//  connect to mysql
$conn=mysql_connect($host,$user,$pass);

//  if cannot connect, exit
if(!$conn){
    die('Cannot connect to MySQL server: '.mysql_errno().' - '.mysql_error());
};

//  if cannot set to utf8, exit
if(!mysql_query('set names utf8;',$conn)){
    mysql_close($conn);
    die('Cannot set to UTF8: '.mysql_errno().' - '.mysql_error());
};

//  if cannot select database, exit
if(!mysql_select_db($dbname,$conn)){
    mysql_close($conn);
    die('Cannot select database: '.mysql_errno().' - '.mysql_error());
};

};


function sql_to_html($x){
return(htmlspecialchars(stripslashes($x),ENT_QUOTES,"UTF-8"));
};


Don't forget to set PHP's internal encoding to UTF8 using iconv_set_encoding. Your php.ini preferences only affect the HTTP headers that are sent with your document! Finally, make sure you pass the encoding to mangling functions like htmlentities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜