ZipArchive::addPattern

Add files from a directory by PCRE pattern

&reftitle.description; public ``array``false```ZipArchive::addPattern` `string` `pattern` `string` `path`"." `array` `options`[]

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.

&reftitle.parameters;

`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`.

&reftitle.returnvalues;

An `array` of added files on success &return.falseforfailure;

&reftitle.examples;

### `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();
    }
    ?>

&reftitle.seealso;

- `ZipArchive::addFile`
- `ZipArchive::addGlob`