epitome
epitome

Reputation: 63

Spanish Characters Not Encoding Correctly

I'm working on a project in the Philippines where many people have special Latin tilde characters in their names.

I have a database set up with all tables in latin1 with latin1_swedish_ci collation.

+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | latin1                         |
| character_set_connection | latin1                         |
| character_set_database   | latin1                         |
| character_set_filesystem | binary                         |
| character_set_results    | latin1                         |
| character_set_server     | latin1                         |
| character_set_system     | utf8                           |
| character_sets_dir       | C:\xampp\mysql\share\charsets\ |
+--------------------------+--------------------------------+

My webpage headers declare iso-8859-1 as the character set.

When I submit an employee name containing a tilde character through my web forms, for example, it appears in my table as 'Marie Cañon' and appears the same on my webpages when I look at the employee's record.

If I change the webpage encoding to utf-8, it displays correctly as 'Marie Cañon'. So, I'm assuming that somehow I'm encoding UTF-8 in my latin1 tables. But I'm confused where that could be occurring.

As far as I know, PDO doesn't deal with encoding. My webpages are declared iso-8859-1, so I'm figuring PHP isn't causing the problem. My character_set_connection is latin1 in MySQL.

Where could this be happening?

Additional Information: Ubuntu 10.04.2 LTS MySQL 5.1.41-3ubuntu12.9-log PHP5: 5.3.2 Apache2: 2.2.14

Upvotes: 2

Views: 12384

Answers (3)

Brian Sanchez
Brian Sanchez

Reputation: 918

This worked for me:

$title = mb_convert_encoding($article['title'], "UTF-8", "iso-8859-1");

for Spanish accents

Upvotes: 6

Raider1980
Raider1980

Reputation: 1

I resolved it when picking up the string from the database adding this:

$var = utf8_encode(strtoupper(mysql_result($query, $i, 0)));

Upvotes: 0

Costis Aivalis
Costis Aivalis

Reputation: 13728

  1. Switch your MySQL to utf-8.
  2. Install the mbstring PHP extension and configure it.
  3. Make your PHP headers: header('Content-type: text/html; charset=UTF-8'); and
  4. HTMLheaders <meta http-equiv="Content-type" value="text/html; charset=UTF-8" /> and
  5. check this cheat sheet.

Upvotes: 5

Related Questions