$zip = new ZipArchive(); $zip->open('archive.zip'); $fileContent = $zip->getFromName('example.txt'); echo $fileContent;
$zip = new ZipArchive(); $zipData = file_get_contents('archive.zip'); $zip->openFromString($zipData); $fileContent = $zip->getFromName('example.txt'); echo $fileContent;In these examples, the ZipArchive class is used to open a ZIP archive and retrieve the contents of a file using the getFromName method. The first example opens the ZIP archive by specifying its filename, while the second example opens a ZIP archive stored in a variable using the openFromString method. Both examples then use getFromName to retrieve the contents of a file named "example.txt". The package library for ZipArchive is built-in to PHP itself, so no external dependencies or installations are necessary.