[英]Preg match all characters for array items
我有一個列出文件夾名稱的數組
$excludes=array("phpMailer","pdf");
我想匹配列出目錄中的所有其他目錄和文件
例如,使用上面的數組,我想使$ excludes數組成為
phpMailer/other-dir/file1.php
phpMailer/other-dir/file2.php
phpMailer/dir2/dir3/file10.php
pdf/file1.php
pdf/dir6/phpfile.php
pdf/folder/dir2/file11.php
等等...對於數組中列出的所有內容
我想也許使用preg_match('/./', $excludes);
會做到的,但是沒有
preg_match('/./', $excludes)
'/./'表示長度為1的任何東西,您應該將其更改為
preg_match('/.*/', $excludes); // which means whatever nevertheless how long it is
您必須使用一個循環。
$excludes = array("phpMailer","pdf");
foreach ($excludes as $exclude) {
if (preg_match($exclude, $fileNameAndPath)) { //$fileNameAndPath - your current file with a complete path
//CODE to exclude...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.