简体   繁体   English

从ISO-8859-1到UTF-8的php应用程序编码问题

[英]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. 我正在尝试将PHP应用程序从ISO-8859-1编码为UTF-8。 Made a test copy of the application, ran the following iconv to recursively modify all files. 制作了该应用程序的测试副本,运行以下iconv以递归方式修改所有文件。

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脚本

<?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

Your files are fine and in UTF-8, you are just interpreting it in CP1252/ISO-8859-1. 您的文件很好,在UTF-8中,您只是在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. 在文本编辑器中,指定文件为UTF-8,它将正确显示字符。 Do not do any conversions. 不要进行任何转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM