update : 2015.11.03
php.shukuma.com

검색:
 
 
Add files from a directory by PCRE pattern

ZipArchive::addPattern

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

ZipArchive::addPatternAdd files from a directory by PCRE pattern

설명

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

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().

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

예제

Example #1 ZipArchive::addPattern() example

Add all php scripts and text files from current directory

<?php
$zip 
= new ZipArchive();
$ret $zip->open('application.zip'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();
}
?>

참고