Reputation: 3021
I have the following error showing up in my error log:
PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Delimiter must not be alphanumeric or backslash in /home/sites/mydomain.com/public_html/public/themes/js/imagegallery.php on line 24, referer: http://www.mydomain.com/collections.html
Here is the preg match it refers to - does anyone have any idea what it relates to exactly?
$iterator = new DirectoryIterator($path);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile() && !preg_match('\.jpg$/', $fileinfo->getFilename())) {
$bgimagearray[] = $fileinfo->getFilename();
}
}
Upvotes: 0
Views: 941
Reputation: 58982
You're missing the first delimiter (/
).
HOWEVER, there is no need for a regex here. You can get the filename by simply doing:
$extension = pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION);
Upvotes: 0
Reputation: 347
The delimiter is referring to the symbols that surround the RegEx you are using. In this case, you use the proper end-delimiter, but not the beginning one. It should look like this: preg_match('/\.jpg$/', ...)
Upvotes: 0
Reputation: 8003
A delimiter is the character used to denote the start and end of a regular expression. Typically people will use something like /
, #
, or @
, but it can be just about any character.
Try this instead:
preg_match('/\.jpg$/', ...
That said, it would probably be better to use substr()
here, no need for regex.
Upvotes: 0
Reputation: 5824
Yup you are not using any delimiters at all in your regex. The engine tries to evaluate the first char in your regex as start-delimiter. Your first char is a backslash. This is not allowed.
Modify your regex this way
!preg_match('#\.jpg$#',....
Upvotes: 0