PHP读Zip文件的方法

function readZip(){
    $zip = zip_open(dirname(__FILE__).'要读的文件');

    $contents = array();
    if ($zip){
        while($zip_entry = zip_read($zip)){
            $name = zip_entry_name($zip_entry);
//            var_dump(zip_entry_name($zip_entry));
            if ($name != '.' && $name != '..' && $name != ''){
                $file = zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
                //$file 为读取到的内容 需做处理并存储数据库 参考get_overview方法
                $key = explode('.',$name);

                $contents[$key[0]] = auto_read($file);

            }
        }
    }
    return $contents;
}

//转码方法
function auto_read($str, $charset='UTF-8') {
    $item = mb_detect_encoding($str,'auto');
    return mb_convert_encoding($str,$charset,$item);
}

转码方法只适应部分的文件,有些文件转码还是会有问题,还在完善。

原文地址:https://www.cnblogs.com/xiledada/p/7410261.html