So I have an array with values, this case file extentions but i'm using preg_match to filter out file extentions that are not allowed.
Is there an easy way to translate an array to an regex pattern?
Source array
(
[1] => 'file-to-path/thumbs/allowedfile.pdf',
[2] => 'file-to-path/thumbs/notallowedfile.psd',
[3] => 'file-to-path/project/test/notallowedfile.txt',
)
Allowed extentions array
(
[0] => bmp
[1] => jpg
[2] => jpeg
[3] => gif
...
)
The code that im using right now.
foreach($array as $key => $val){
if( !preg_match('/^.*\.(jpg|png|jpeg|bmp|gif|pdf)$/i', $val ) ){
// this part needs to be an array
'/^.*\.(jpg|png|jpeg|bmp|gif|pdf)$/i' -> [array with the values]
}
}
array_filter
(secure.php.net/manual/en/function.array-filter.php)