Sample code for 30+ languages & platforms
PHP Extension

Unzip Text File to String

See more Zip Examples

Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.

Chilkat PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

$success = false;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$zip = new CkZip();

$success = $zip->OpenZip('qa_data/zips/EC16100.zip');
if ($success == false) {
    print $zip->lastErrorText() . "\n";
    exit;
}

// Get the 1st file in the .zip
$entry = new CkZipEntry();
$success = $zip->EntryAt(0,$entry);
if ($success == false) {
    print $zip->lastErrorText() . "\n";
    exit;
}

$fileContents = $entry->unzipToString(0,'utf-8');
print $fileContents . "\n";

?>