judbd
1
Is it possible to use regexp to find a file with one of these functions : find()
, filterBy()
or file()
(or another one) ?
for the moment I have :
<?php if($cvfiles = $page->files()->filterBy('extension', 'pdf')->filterBy('filename', '*=', 'cv')->filterBy('filename', '*=', 'dl')): ?>
but maybe there is a simpler way to do it with regex and/or joker characters like *
Thank You
judbd
3
Like this ?
$cvfiles = $page->files()->filter(function($image) {
return $cvfile->filename() == preg_match("myregexp", $cvfile->filename());
});
Do I need a foreach after that ?
Yes, $cvfiles
a normal filtered collection.
1 Like
Well, almost. It has to be like this:
$cvfiles = $page->files()->filter(function($image) {
return preg_match('/myregexp/', $cvfile->filename());
});
1 Like