3v4l.org

run code in 300+ PHP versions simultaneously
<?php $zipFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'filename.zip'; $password = 'P455W0RD'; if (file_exists($zipFilePath)) { unlink($zipFilePath); } $zipArchive = new ZipArchive(); $zipArchive->open($zipFilePath, ZipArchive::CREATE); if ($zipArchive->setPassword($password)) { echo 'OK' . PHP_EOL; } foreach (range(1, 10) as $fileNumber) { $zipArchive->addFromString('file' . $fileNumber . '.txt', rand()); } $zipArchive->close();

preferences:
30 ms | 402 KiB | 5 Q