>백엔드 개발 >PHP 튜토리얼 >压缩-php获取rar文件里面的内容,输出来如何解析?

压缩-php获取rar文件里面的内容,输出来如何解析?

不言
不言원래의
2018-05-26 15:29:491966검색

压缩扩展php数组对象

最近有一个需求:将rar压缩文件里面的文件名、大小获取出来,解析成json输出来;
查阅了无数资料,得知添加php_rar.dll(如果是zip的话,就添加php_zip.dll扩展),最后通过程序得到rar的相关内容,但对里面获取到的内容格式不知道怎么解析成json,求大神指点一二。

$rar_file = rar_open('222.rar') or die("Failed to open Rar archive");
$entries_list = rar_list($rar_file);
header('Content-Type: text/plain');
print_r($entries_list);

得到数据如下:

Array
(
    [0] => RarEntry Object
        (
            [rarfile:RarEntry:private] => RarArchive Object
                (
                )
       
     [position:RarEntry:private] => 0        
     [name:RarEntry:private] => tar.php        
     [unpacked_size:RarEntry:private] => 64332        
     [packed_size:RarEntry:private] => 11726        
     [host_os:RarEntry:private] => 2        
     [file_time:RarEntry:private] => 2012-07-09 23:47:06        
     [crc:RarEntry:private] => 69e1487f        
     [attr:RarEntry:private] => 128        
     [version:RarEntry:private] => 29        
     [method:RarEntry:private] => 51        
     [flags:RarEntry:private] => 32928    )
     [1] => RarEntry Object    (        
     [rarfile:RarEntry:private] => RarArchive Object            (            )        
     [position:RarEntry:private] => 1        
     [name:RarEntry:private] => upload.php        
     [unpacked_size:RarEntry:private] => 2461        
     [packed_size:RarEntry:private] => 1033        
     [host_os:RarEntry:private] => 2        
     [file_time:RarEntry:private] => 2012-07-09 23:47:06        
     [crc:RarEntry:private] => ecc4a20d        
     [attr:RarEntry:private] => 128        
     [version:RarEntry:private] => 29        
     [method:RarEntry:private] => 51        
     [flags:RarEntry:private] => 32928    )
     [2] => RarEntry Object    (        
     [rarfile:RarEntry:private] => RarArchive Object            (            )        
     [position:RarEntry:private] => 2        
     [name:RarEntry:private] => urlupload.php        
     [unpacked_size:RarEntry:private] => 1877        
     [packed_size:RarEntry:private] => 864        
     [host_os:RarEntry:private] => 2        
     [file_time:RarEntry:private] => 2012-07-09 23:47:06        
     [crc:RarEntry:private] => 44a999a9        
     [attr:RarEntry:private] => 128        
     [version:RarEntry:private] => 29        
     [method:RarEntry:private] => 51        
     [flags:RarEntry:private] => 32928    )
     [3] => RarEntry Object    (        
     [rarfile:RarEntry:private] => RarArchive Object            (            )        
     [position:RarEntry:private] => 3        
     [name:RarEntry:private] => user.php        
     [unpacked_size:RarEntry:private] => 402        
     [packed_size:RarEntry:private] => 222        
     [host_os:RarEntry:private] => 2        
     [file_time:RarEntry:private] => 2012-07-09 23:47:06        
     [crc:RarEntry:private] => 22db657e        
     [attr:RarEntry:private] => 128        
     [version:RarEntry:private] => 29        
     [method:RarEntry:private] => 51        
     [flags:RarEntry:private] => 32928    )  )
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.