Reputation: 23
I have a php code that needs to be matched for any of the following string using preg_match using this code
if(preg_match('/(image/gif)|(image/jpg)|(image/jpeg)/',$between))
{
echo "Match Found";
}
else
echo "Match Not Found";
but i get this error
Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:\xampp\htdocs\project\extension.php on line 38
Any help will be appreciated....I googled alot but couldn't find solution...
Upvotes: 1
Views: 129
Reputation: 254926
As long as you want /
to be used inside regular expression - use ~
as a regex delimiter instead:
if(preg_match('~(image/gif)|(image/jpg)|(image/jpeg)~',$between))
^----------- ^--------
or even better:
if(preg_match('~image/(gif|jpe?g)~',$between))
Upvotes: 0
Reputation: 13257
Replace your preg_match pattern with this:
'/(image\/gif)|(image\/jpg)|(image\/jpeg)/'
You should always escape characters like /
Upvotes: 1
Reputation: 437386
You are using /
as the delimiter character, so when it appears inside your regex you must escape it:
if(preg_match('/(image\/gif)|(image\/jpg)|(image\/jpeg)/',$between))
Alternatively, you can choose another delimiter:
if(preg_match('~(image/gif)|(image/jpg)|(image/jpeg)~',$between))
Upvotes: 1