Adrian Ilie
Adrian Ilie

Reputation: 133

encoding Romanian characters in php

i have o problem encoding characters that look like this: ĂăÂâÎîȘșȚț i am using the following mysql table:

CREATE TABLE `news` (
  `NewsID` int(11) NOT NULL AUTO_INCREMENT,
  `UserID` int(11) NOT NULL,
  `Title` varchar(255) CHARACTER SET utf8 NOT NULL,
  `Date` datetime NOT NULL,
  PRIMARY KEY (`NewsID`),
  FULLTEXT KEY `Title` (`Title`,`Content`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_bin

I try to insert the upper mentioned character sequence in the Title field by using the following code (runs on zend framework):

$params = $this->getRequest()->getParams(); 
$mysqli = new mysqli("localhost", "user", "pass", "database_name");
$mysqli->query("INSERT INTO `news` (`NewsID`, `Title`) VALUES (NULL, '".$params['text']."');");

And in the database i get for the field Title the following value: ÃãÂâÎîȘșȚț Why are these characters html encoded? And why aren't the first characters encoded to their utf8_bin equivalent ? Thanks.

Upvotes: 0

Views: 4429

Answers (3)

mariusag
mariusag

Reputation: 101

In my case I just updated php db connection settings with the following line:

mysqli_set_charset( $con, 'utf8'); 

Also i added in html file meta http-equiv="content-type" content="text/html; charset=UTF-8" as @liyakat mentioned.

Old thread, but maybe someone needs to know this.

Upvotes: 3

liyakat
liyakat

Reputation: 11853

To set the default to UTF-8, you want to add the following to my.cnf

[client] default-character-set=utf8

[mysqld] default-character-set = utf8 Then, to verify:

mysql> show variables like "%character%";show variables like "%collation%";

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

OR TRY

Try setting the MySQL connection to UTF-8:

SET NAMES 'utf8'

And send explicit UTF-8 headers, just in case your server has some other default settings:

header('Content-type: text/html; charset=utf-8');

Upvotes: 0

Expedito
Expedito

Reputation: 7795

Be sure that your IDE or text editor is also set to use UTF-8 characters.

Upvotes: 0

Related Questions