I have this string in a php variable.
$str = 'This is an iamge: <img src="images/Christmas.PNG" width=70%; height=40%">';
The pattern I am searching:
$pattern = '/<img src="(.*?)>/g';
I then have this preg_match()
preg_match($pattern, $str, $matches, PREG_OFFSET_CAPTURE);
When i go to print $matches
either directly by echo $matches
or in a foreach loop, the variable is null.
Why is this happening? Thanks.
g
global flag in PHP. Usepreg_match_all
for getting all matches. Further your pattern would matchimages/Christmas.PNG" width=70%; height=40%"
probably you wanted<img src="([^"]+)