You have to escape the slashes (/
) in the regex:
/<a href="http:\/\/from.ae\/cameras-photo\/digital-cameras\/samsung-es95-white"><img id="img_(.*?)"/mis
Because you used /
as your delimiter, PHP assumes everything after the second /
is a modifier. In this case, that's another /
, which is not a valid modifier.
You can do the escaping with preg_quote
, like this:
$text = '<a href="http://from.ae/cameras-photo/digital-cameras/samsung-es95-white"><img id="img_28300"';
$regex = '/'.preg_quote('<a href="http://from.ae/cameras-photo/digital-cameras/samsung-es95-white"><img id="img_', '/').'(.*?)"/mis';
var_dump($regex);
var_dump( preg_match($regex, $text) );
Demo
An even simpler solution, as pointed out in the comments, is just to use a different delimiter. I'm fond of ~
, but any character will work:
$text = '<a href="http://from.ae/cameras-photo/digital-cameras/samsung-es95-white"><img id="img_28300"';
$regex = '~<a href="http://from.ae/cameras-photo/digital-cameras/samsung-es95-white"><img id="img_(.*?)"~mis';
var_dump($regex);
var_dump( preg_match($regex, $text) );
Demo