zip_entry_read()函数是PHP中内置的函数,用于从翻开的zip归档条目中读取内容。正在读取zip条目,返回的字节数能够作为参数发送给zip_entry_read()函数,假如胜利,它将返回指定zip条目的内容,不然将返回PHP正告。
语法:
string zip_entry_read( $zip_entry, $length )
参数:
该函数接收两个参数,以下所述。
$zip_entry:这是一个指定zip条目资本的强迫参数。
$length:它是一个可选参数,指定要返回的字节数。
返回值:
胜利时返回指定zip条目的内容,不然返回PHP正告。
毛病和非常:
假如zip存档无效,zip_entry_read()函数将返回ER_OPEN毛病。
假如zip存档为空,则zip_entry_read()函数返回ER_NOZIP毛病
下面的顺序演示了PHP中的zip_entry_read()函数:
示例1:
假定zip文件article.zip包括文件:geeks.txt
<?php // 翻开zip文件 $zip_handle = zip_open("C:/xampp/htdocs/articles.zip"); // 读取zip存档项 while($zip_entry = zip_read($zip_handle)) { $resource = zip_entry_open($zip_handle, $zip_entry, "rb"); $file_name = zip_entry_name($zip_entry); if ($resource == true) { // 读取zip存档项的内容 $file_content = zip_entry_read($zip_entry); echo("File: " . $file_name . " successfully opened. <br>"); echo("File content: " . $file_content); // 封闭zip归档项 zip_entry_close($zip_entry); } else echo("Failed to Open."); } // 封闭zip文件 zip_close($zip_handle); ?>
输出:
File: articles/geeks successfully opened. File content: Welcome to GeeksforGeeks. It is a computer science portal where you can learn programming.
示例2:
假定zip文件article.zip包括以下文件:
geeks.txt
geeks1.txt
<?php $zip_handle = zip_open("C:/xampp/htdocs/articles.zip"); while($zip_entry = zip_read($zip_handle)) { $resource = zip_entry_open($zip_handle, $zip_entry, "rb"); $file_name = zip_entry_name($zip_entry); if ($resource == true) { // 读取zip存档项的内容,最多可达150字节 $file_content = zip_entry_read($zip_entry, 150); echo("File Name: " . $file_name . " is opened Successfully. <br>"); echo($file_content); echo("<br><br>"); zip_entry_close($zip_entry); } else echo("Failed to Open."); } zip_close($zip_handle); ?>
输出:
File Name: articles/geeks is opened Successfully. Welcome to GeeksforGeeks. It is a computer science portal where you can learn programming. File Name: articles/geeks1 is opened Successfully. A Computer Science portal for geeks. It contains well written, well thought and well-explained computer science and programming articles, quizzes and many more.
相干引荐:《PHP教程》
以上就是php怎样读取zip内容?(zip_entry_read函数的运用)的细致内容,更多请关注ki4网别的相干文章!