$zip = new ZipArchive(); $zip->open('example.zip'); // retrieve contents of the file at index 0 $fileContents = $zip->getFromIndex(0); echo $fileContents;
$zip = new ZipArchive(); $zip->open('example.zip'); // loop through all files in the archive and output their contents for ($i = 0; $i < $zip->numFiles; $i++) { echo $zip->getFromIndex($i) . 'This example loops through all files in the archive and outputs their contents. The getFromIndex method is called for each file in the loop, using the index variable. The package library used to access the ZipArchive class is included in the core PHP language and does not require any external dependencies or installations.
'; } $zip->close();