bobsr
bobsr

Reputation: 3955

Php application encoding problems from ISO-8859-1 to UTF-8

I am trying to encode php application from ISO-8859-1 to UTF-8. Made a test copy of the application, ran the following iconv to recursively modify all files.

find . -type f -print -exec iconv -f iso8859-1 -t utf-8 -o {}.converted {} \; -exec mv {}.converted {} \;

The above did not really do the work. The code still has text like:

não exibe nenhuma info durante a configuração. será setado adequadadmente

With a test php script

<?php
$text = "não exibe nenhuma info durante a configuração. será setado adequadadmente";

echo 'Original : ', $text, PHP_EOL;
echo 'TRANSLIT : ', iconv("ISO-8859-1", "UTF-8//TRANSLIT", $text), PHP_EOL;
echo 'IGNORE   : ', iconv("ISO-8859-1", "UTF-8//IGNORE", $text), PHP_EOL;
echo 'Plain    : ', iconv("ISO-8859-1", "UTF-8", $text), PHP_EOL;

?>

the output is:

Original : não exibe nenhuma info durante a configuração. será setado adequadadmente
TRANSLIT : não exibe nenhuma info durante a configuração. será setado adequadadmente
IGNORE   : não exibe nenhuma info durante a configuração. será setado adequadadmente
Plain    : não exibe nenhuma info durante a configuração. será setado adequadadmente

Upvotes: 1

Views: 1564

Answers (1)

Esailija
Esailija

Reputation: 140210

Your files are fine and in UTF-8, you are just interpreting it in CP1252/ISO-8859-1. You need to declare encoding to the browser and your text editor.

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

In your text editor, specify that the file is in UTF-8, and it will show the characters correctly. Do not do any conversions.

Upvotes: 1

Related Questions