Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-如何检测ANSI文本文件?_Php - Fatal编程技术网

PHP-如何检测ANSI文本文件?

PHP-如何检测ANSI文本文件?,php,Php,我想检测文件编码是ANSI还是UTF-8和Unicode。我只知道如何检测UTF-8 if (mb_detect_encoding(file_get_contents($file), 'UTF-8', true)) { echo "UTF-8"; } /*指定编码\u按逗号分隔列表进行字符编码*/ echo mb_detect_encoding($str, "ASCII, UTF-8, UNICODE"); 它将根据列表打印检测到的编码没有ANSI文本之类的东西。您必须检查特定的遗留

我想检测文件编码是ANSI还是UTF-8和Unicode。我只知道如何检测UTF-8

if (mb_detect_encoding(file_get_contents($file), 'UTF-8', true))
{
    echo "UTF-8";
}

/*指定编码\u按逗号分隔列表进行字符编码*/

echo mb_detect_encoding($str, "ASCII, UTF-8, UNICODE");

它将根据列表打印检测到的编码

没有ANSI文本之类的东西。您必须检查特定的遗留字符集。或者ASCII,如果这是你的意思的话。你真正能做的就是检查一个文件是否是无效的UTF-8。除此之外,这几乎是猜测。看看这个链接@imbignob没有“Unicode”编码。