首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ZipArchive::addPattern

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

ZipArchive::addPattern - 通过PCRE模式从目录添加文件

描述

代码语言:javascript
复制
bool ZipArchive::addPattern ( string $pattern [, string $path = "." [, array $options = array() ]] )

从与正则表达式匹配的目录添加文件pattern。该操作不是递归的。该模式将仅与文件名匹配。

参数

pattern

PCRE模式对哪些文件进行匹配。

path

将被扫描的目录。默认为当前工作目录。

options

ZipArchive::addGlob()接受的选项的关联数组。

返回值

成功时返回TRUE或失败时返回FALSE

示例

Example #1 ZipArchive::addPattern() example

从当前目录添加所有php脚本和文本文件

代码语言:javascript
复制
<?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();
}
?>

另请参阅

  • ZipArchive::addFile() - 将文件从给定路径添加到ZIP归档文件中
  • ZipArchive::addGlob() - 通过glob模式从目录添加文件

← ZipArchive::addGlob

ZipArchive::close →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com