Friday, October 17, 2025
HomeLanguagesPHP ZipArchive getArchiveComment() Function

PHP ZipArchive getArchiveComment() Function

The ZipArchive::getArchiveComment() function is an inbuilt function in PHP that is used to return the zip archive comment.

Syntax:

string|false ZipArchive::getArchiveComment(int $flags = 0)

Parameters: This function accepts a single parameter that is described below.

  • $flag: This parameter holds the flag and if the flag is set to  ZipArchive::FL_UNCHANGED, then an unchanged archive comment is returned.

Return Value: This function returns the zip archive comment or “false” on failure.

Example 1: The following code demonstrates the getArchiveComment() function.

PHP




<?php
 
    // Create a new ZipArchive object
    $zip = new ZipArchive;
 
    // Check for opening the zip file
    if ($zip->open('Geeks.zip', ZipArchive::CREATE))
    {
         
        // Get the archive comment
        var_dump($zip->getArchiveComment());
         
        // Close the zip file
        $zip->close();
    }
    // If zip file is not open/exist
    else {
        echo 'Failed to open zip file';
    }
?>


Output:

string(0) ""

Example 2: The following code demonstrates the setArchiveComment() function which set the given string as shown in the output.

PHP




<?php
 
    // Create a new ZipArchive object
    $zip = new ZipArchive;
 
    // Check for opening the zip file
    if ($zip->open('Geeks.zip', ZipArchive::CREATE)) {
         
        $zip->setArchiveComment('neveropen Archive Comment');
         
        var_dump($zip->getArchiveComment());
         
        // Close the zip file
        $zip->close();
    }
    // If zip file is not open/exist
    else
    {
        echo 'Failed to open zip file';
    }
?>


Output:

string(29) "neveropen Archive Comment"

Reference: https://www.php.net/manual/en/ziparchive.getarchivecomment.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS