Problems with PHP / MySQL encoding. â instead of certain characters

I ran into some problems when entering certain characters into my mysql database using php. What I am doing is user-entered text in a database. I can't figure out what I need to change to allow any character to fit into the database and print back through php, as he believes.

My MySQL collation: latin1_swedish_ci

Just before sending text to the database from my form, I use mysql_real_escape_string () for the data.

Example below

this text:

â  People are just as happy as they make up their minds to be.â  
â   Abraham Lincoln 

Suppose it looks like this:

"People are just as happy as they make up their minds to be."
― Abraham Lincoln
+2
source share
6 answers

, UTF8 , "" . -, PHP, mysql mysql. - , UTF8. UTF8.

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

PHP UTF8. , , , :

mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');

mysql UTF8, /.

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8

mysql utf8. :

 SET NAMES UTF8

"" UTF8.

.

+7

, latin1, , UTF-8. - , :

$quote = iconv("UTF-8", "WINDOWS-1252//TRANSLIT", $quote);

(, MySQL latin1, - windows-1252 .) , , U + 2015, , - . utf8.

: utf8. , : MySQL , latin1, . ( , U + 2015 ?, latin1)

: MySQL, mysql_set_charset, MySQLi mysqli_set_charset, PDO encoding=utf8 DSN.

, UTF-8 Content-Type. : , UTF-8, - :

header("Content-Type: text/html; charset=utf-8");
+3

, . UTF-8 . UTF-8 ​​ .

:

  • , (tmp_)
  • db- utf8, , utf8_bin,
  • char LATIN1 UTF-8. . char -, LATIN1,
  • tmp_tables ,

, :

$chars = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, "UTF-8");
$LATIN1 = $UTF8 = array();
while (list($key,$val) = each ($chars)) {
    $UTF8[] = $key;
    $LATIN1[] = $val;
}

: ( → ) rows- >

$row[$field] = mysql_real_escape_string(str_replace($LATIN1 , $UTF8 , $row[$field]));
$q[] = "$field = '{$row[$field]}'";

, :

mysql_query("UPDATE $table SET " . implode(" , " , $q) . " WHERE id = '{$row['id']}' LIMIT 1");
+1

MySQL utf8_unicode_ci utf8_general_ci, .

0

utf-8 yes. . , phpmyadmin php ( ) mysql.

, , , .

, , , , .

: http://dev.mysql.com/doc/refman/5.6/en/charset-syntax.html

, apache. " ", . charater . , Apache.

0

, , , , , .

1- , utf8_general_ci.

2- define <meta http-equiv="content-type" content="text/html; charset=utf-8">in HTML after the header.

2- You need to determine mysql_set_charset('utf8',$link_identifier);in the file where you established the connection to the database, and immediately after choosing a database, such as "mysql_select_db", use this "mysql_set_charset", this will allow you to correctly add and retrieve data in whatever language it is .

0
source

All Articles