PHP preg_grep multi files

177 views Asked by At

how can I exclude more files like branding.php? For example branding.php, about.php, contact.php.

$pages = preg_grep('/branding\.php/', glob("*.php"), PREG_GREP_INVERT);

Thx.

1

There are 1 answers

1
Toto On BEST ANSWER

Use alternative in the regex:

$pages = preg_grep('/\b(?:branding|about|contact)\.php/', glob("*.php"), PREG_GREP_INVERT);

Where

  • \b   : word boundary to avoid matching abranding or abc123about ...
  • (?:branding|about|contact) : non capture group that match branding OR about OR contact (you may add more files)