Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน zip_entry_read() ใน PHP

ฟังก์ชัน zip_entry_read() ใช้สำหรับดึงเนื้อหาจากไฟล์ในอาร์คีฟ ZIP ที่เปิดอยู่

รูปแบบการใช้งาน (Syntax)

zip_entry_read(zip_entry, len)

พารามิเตอร์ (Parameters)

  • zip_entry − ทรัพยากร zip entry (จำเป็น)

  • len − ความยาวในหน่วยไบต์ ค่าเริ่มต้นคือ 1024

ค่าที่ส่งกลับ (Return Value)

ฟังก์ชัน zip_entry_read() ส่งคืนเนื้อหาจากไฟล์ในอาร์คีฟ ZIP ที่เปิดอยู่ ส่งคืน FALSE เมื่อล้มเหลว

ตัวอย่างการใช้งาน

ตัวอย่าง สมมติว่าไฟล์ ZIP "one.zip" มีไฟล์เดียวคือ "detail.txt" ด้วยเนื้อหา:

Asia is a continent!
<?php 
$zip_file = zip_open("one.zip"); 
if ($zip_file) { 
    while ($zip_entry = zip_read($zip_file)) { 
        if (zip_entry_open($zip_file, $zip_entry)) { 
            echo "Text in the file = <br/>"; 
            echo zip_entry_read($zip_entry) . "<br />"; 
            zip_entry_close($zip_entry); 
        } 
        echo "</p>"; 
    } 
    zip_close($zip_file); 
} 
?>

ผลลัพธ์ (Output)

Text in the file = Asia is a continent!