當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP ZipArchive getArchiveComment()用法及代碼示例

ZipArchive::getArchiveComment() 函數是 PHP 中的內置函數,用於返回 zip 存檔注釋。

用法:

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

參數:該函數接受如下所述的單個參數。

  • $flag:此參數保存標誌,如果該標誌設置為 ZipArchive::FL_UNCHANGED,則返回未更改的存檔注釋。

返回值:此函數在失敗時返回 zip 存檔注釋或“false”。

示例 1:下麵的代碼演示了getArchiveComment()函數。

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';
    }
?>

輸出:

string(0) ""

示例 2:下麵的代碼演示了setArchiveComment()函數設置給定的字符串,如輸出所示。

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('GeeksforGeeks 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';
    }
?>

輸出:

string(29) "GeeksforGeeks Archive Comment"

參考: https://www.php.net/manual/en/ziparchive.getarchivecomment.php



相關用法


注:本文由純淨天空篩選整理自vkash8574大神的英文原創作品 PHP ZipArchive getArchiveComment() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。