phpday 2027 - Call for Papers

ZipArchive::closeString

(PHP >= 8.6.0)

ZipArchive::closeString — Close the active archive and return it as a string

说明

public function ZipArchive::closeString(): string|false

Closes an archive that was opened with ZipArchive::openString(), saves any changes, and returns the resulting archive as a string.

注意:

As with ZipArchive::close(), a new archive that contains no entries is not written. In that case an empty string is returned, which is not a valid ZIP archive.

参数

此函数没有参数。

返回值

Returns the contents of the archive as a string, or false on failure. When it fails, a warning is raised and the reason is available from ZipArchive::getStatusString().

错误/异常

Throws an Error if the archive was not opened with ZipArchive::openString(), and a ValueError if the archive is not open, for example because it has already been closed.

示例

示例 #1 Building an archive in memory

<?php
$zip = new ZipArchive;
$zip->openString();
$zip->addFromString('hello.txt', "Hello\n");
$bytes = $zip->closeString();

var_dump(is_string($bytes), str_starts_with($bytes, "PK"));
?>

以上示例会输出:

bool(true)
bool(true)

参见

+添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top