Hi all! I have in my database's table records with fields of VARCHAR(100) of charset utf-8 general-ci. When I echo it to the web page, it echos string and many-many some square symbols. How can I delete them and leave inly word. Wthas the problem. W开发者_运维百科ill be a problem with searching? Thanx!
Is the script encoded in UTF-8 and do you also UTF8 for the connection to the database? You can set the charset of the connection using the following query directly after connecting
SET NAMES 'UTF8'
You are a PHP nerd and just started to work with PHP and mysql. In order to work unicode data you need to know something before proceeding.
First make sure your table fields are set to use “utf8_general_ci” collation to accept all languages character sets. Of course you can use any other collation starting with “utf8_” for example if your database needs only English and Persian characters you can choose “utf8_persian_ci”.
Second: When writing some PHP code working with MYSQL you need to explicitly ask PHP to transfer your uni-code data in utf8 format so it will match the destination data type which is utf8. This will cause the client`s data to be stored “as-is” in MYSQL.
If you don`t follow this rule MYSQL will store your utf8 data as question marks.
In order to avoid this to happen you only need to write the following line before any query in your PHP code.
mysql_query("SET NAMES 'UTF8'");
So, first we need to connect to the database. Second, call
mysql_query("SET NAMES 'UTF8'");
Third, do other operations.
I would try utf8_decode($string);
Don't forget to set the character encoding on your webpage
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
精彩评论