Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

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 Downloads

PHP
<?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();

try {
    $zip->OpenZip('qa_data/zips/EC16100.zip');

    // Get the 1st file in the .zip
    $entry = new ZipEntry();
    $zip->EntryAt(0, $entry);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$fileContents = $entry->UnzipToString(0, 'utf-8');
echo $fileContents, "\n";