PHP Requires Chilkat v11.0.0+
Chilkat2 PHP
Iterate over Matching Filenames
See more Zip Examples
Iterates over files within a .zip that match a pattern. In this case, the pattern is "*.pem". This example will open a .zip containing files of type .txt, .cer, .pem, and possibly others, and will iterate over only the .pem files.Chilkat PHP Downloads
<?php
use Chilkat2\Zip;
use Chilkat2\ZipEntry;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$zip = new Zip();
// Open a .zip containing PEM files, among other things..
try {
$zip->OpenZip('qa_data/certs/thawte-roots.zip');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$entry = new ZipEntry();
$pemStr = '';
$pattern = '*.pem';
try {
$zip->EntryMatching($pattern, $entry);
$bHasMoreMatches = true;
} catch (\Chilkat2\Exception $e) {
$bHasMoreMatches = false;
}
while ($bHasMoreMatches) {
echo 'Entry: ', $entry->FileName, "\n";
// Get the uncommpressed contents of the entry:
$pemStr = $entry->UnzipToString(0, 'utf-8');
echo $pemStr, "\n";
$bHasMoreMatches = $entry->GetNextMatch($pattern);
}