Patrick Maciel
Patrick Maciel

Reputation: 4944

Convert different encode charset to UTF-8

I have this words (and more 40 in same case) in customer databases:

  1. Aclimação
  2. Aclima&ccedilão

I need convert both to UTF-8 and save in MySQL database: Aclimação.

How I do that with PHP?

[EDIT]
Observation:
I need do that because, when user find specific 'district', its impossible convert in two formats, for example:

  1. Aclimaç&aatilde;o (correct)
  2. Aclimação (incorrect: utf8 + html number encode)
  3. Aclima&ccedilão (incorrect: iso + html number encode)

I need just 1 type of encode, in my case: ISO-8859-1.

Upvotes: 1

Views: 292

Answers (3)

Patrick Maciel
Patrick Maciel

Reputation: 4944

How did the following solution, converted all data from the database, using the function:

mb_convert_encoding (data, 'UTF-8', 'HTML-ENTITIES');

When I read the record, do the following:

utf8_decode (data)

When I look for some record, based on the selection of sites (), I do the following:

utf8_encode (data)

And so far, worked perfectly.

Upvotes: 1

eis
eis

Reputation: 53462

  1. dump your database contents out of there using mysqldump
  2. iconv the data to UTF8
  3. string replace your malformed html entitys to be valid
  4. use html_entity_decode to change valid html entitys to characters that they should be. note that you should give it encoding (UTF-8) as parameter, otherwise it will depend on the PHP version!
  5. create new UTF-8 database into mysql
  6. import the data to mysql

I don't think for example ã exists in ISO-8859-1, so you do actually need UTF-8 for it. It is not correct to have it as &aatilde;, that is HTML way of representing it.

Upvotes: 1

user1598585
user1598585

Reputation:

Get the values and insert them to the database after applying html_entity_decode() to the string.

(The second string you provided looks like it has a malformed HTML entity, is that right?)

Upvotes: 1

Related Questions