略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ZipArchive::addPattern

2024-11-13

ZipArchive::addPattern

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL zip >= 1.9.0)

ZipArchive::addPatternAdd files from a directory by PCRE pattern

说明

public ZipArchive::addPattern(string $pattern, string $path = ".", array $options = []): array|false

Add files from a directory which match the regular expression pattern. The operation is not recursive. The pattern will be matched against the file name only.

参数

pattern

A PCRE pattern against which files will be matched.

path

The directory that will be scanned. Defaults to the current working directory.

options

An associative array of options accepted by ZipArchive::addGlob().

返回值

An array of added files on success 或者在失败时返回 false

范例

示例 #1 ZipArchive::addPattern() example

Add all php scripts and text files from current directory

<?php
$zip 
= new ZipArchive();
$ret $zip->open('application.zip'ZipArchive::CREATE ZipArchive::OVERWRITE);
if (
$ret !== TRUE) {
    
printf('Failed with code %d'$ret);
} else {
    
$directory realpath('.');
    
$options = array('add_path' => 'sources/''remove_path' => $directory);
    
$zip->addPattern('/\.(?:php|txt)$/'$directory$options);
    
$zip->close();
}
?>

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/ziparchive.addpattern.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3