LZ 的 id 看着眼熟 ... 这么多年了还在问这个等级的问题 ... 你也不容易啊你 ...
<?php
/* well ... prepare our zip file ... */
$zip = new ZipArchive;
$res = $zip->open( '/path/to/your.zip' );
/* can not open ..? are you kidding me ..? */
if ( true !== $res )
throw new Exception( 'Can Not Open Zip File / ' . $res );
/* default value of file encoding ... */
$encoding = 'EMTPY';
/* controller ... change this if mb_detect_encoding return wrong answer ... */
$controller = null;
/* get file list ... */
for ( $i = 0; $i < $zip->numFiles; ++ $i ) {
/* get file encoding ... */
$encoding = mb_detect_encoding( $zip->getNameIndex( $i ), $controller );
/* we do not need english named files ... */
if ( 'ASCII' !== $encoding ) break;
}
/* clean table ... */
$zip->close();
/* simply output ... */
echo $encoding;
代码就是这样了 ... 根据文件名来判断系统 ...
简体中文的 windows 会返回 EUC-CN ... 繁体中文我猜测应该是 EUC-TW 或者 BIG5 ...
Linux 和 MacOS 都是 UTF-8 ... 纯英文的文件就别捣乱了 ...