PHP Ansi 转 UTF-8 [英] PHP Ansi to UTF-8

查看:52
本文介绍了PHP Ansi 转 UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 PHP 创建一个脚本,用于将一些文件转换为 UTF-8.我有一个希腊语文件,其中 Notepad++ 表示它是ANSI"编码.当我将它上传到服务器时,它检测到它的编码为 UTF-8(我认为是 wrinf).然后,当我使用 utf8_encode () 将其内容转换为 UTF-8 并下载新文件时,字符被弄乱了.我试图用 PHP 删除 BOM,结果是一样的.我试图用 PHP 删除 BOM 而不将文件转换为 UTF-8,但该文件仍为 ANSI 编码,没有弄乱字符.我该如何解决?

I'm trying to create a script in PHP for converting some files to UTF-8. I have a file in Greek, where Notepad++ indicates that it ahs "ANSI" encoding. When I upload it to the server, it detects it's encoding as UTF-8 (something wrinf i think). Then when I convert it's contents to UTF-8 with utf8_encode () and download the new file, the characters are messed up. I tried to remove the BOM with PHP and the result was the same. I tried to remove the BOM with PHP without converting the file to UTF-8 but the file remained in ANSI encoding, without messed up characters. How can I fix that?

推荐答案

移除 BOM,然后执行:

Remove BOM, then do:

$file = file_get_contents('file.php');
$file = iconv('greek-charset','UTF-8', $file);
file_put_contents('file.php', $file);
//ta-da!

greek-charset 更改为正确的字符集名称(可能是 Windows-1253).

Change greek-charset to correct name of charset (maybe Windows-1253).

这篇关于PHP Ansi 转 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆