zip_entry_read()函数是PHP中的一个内置函数,用于从打开的zip存档条目中读取内容。正在读取zip条目,要返回的字节数可以作为参数发送给zip_entry_read()函数,成功后返回指定zip条目的内容,否则返回PHP警告。
null
语法:
string zip_entry_read( $zip_entry, $length )
参数: 此函数接受两个参数,如上所述,如下所述。
- $zip_入口: 它是一个强制参数,用于指定zip条目资源。
- $length: 它是一个可选参数,指定要返回的字节数。
返回值: 如果成功,它将返回指定zip条目的内容,否则将返回PHP警告。
错误和例外:
- 如果zip存档无效,zip_entry_read()函数将返回一个ER_OPEN错误。
- 如果zip存档为空,zip_entry_read()函数将返回一个ER_NOZIP错误。
下面的程序演示了PHP中的zip_entry_read()函数:
项目1:
假设一篇zip文件文章。zip包含以下文件: 极客。txt
<?php // Opening a zip file $zip_handle = zip_open( "C:/xampp/htdocs/articles.zip" ); // Reading a zip archive entry 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) { // Reading contents of a zip archive entry $file_content = zip_entry_read( $zip_entry ); echo ( "File: " . $file_name . " successfully opened. <br>" ); echo ( "File content: " . $file_content ); // Closing a zip archive entry zip_entry_close( $zip_entry ); } else echo ( "Failed to Open." ); } // Closin zip file. 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文件文章。zip包含以下文件: 极客。txt 极客1。txt
<?php // Opening a zip file $zip_handle = zip_open( "C:/xampp/htdocs/articles.zip" ); // Reading a zip archive entry 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) { // Reading contents of a zip archive entry upto 150 bytes $file_content = zip_entry_read( $zip_entry , 150); echo ( "File Name: " . $file_name . " is opened Successfully. <br>" ); echo ( $file_content ); echo ( "<br><br>" ); // Closing a zip archive entry zip_entry_close( $zip_entry ); } else echo ( "Failed to Open." ); } // Closing a zip archive 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.
相关文章:
参考: http://php.net/manual/en/function.zip-entry-read.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END