I am trying to get all images path from a simple HTML code using preg_match function but I did not get it right. here is my code:
$meta='<img src=\"imgdir/4fd60181316c0cb257628528adb1c342.gif\"><br><img src=\"imgdir/e2326f439cc5f8c201b411bd66eaf9a0.gif\"><br>';
$pattern = "/^imgdir\/[a-zA-Z0-9].*(png|jpg|gif)/i";
preg_match($pattern, $meta, $result);
print_r($result);
please help me to get all images path. example: imgdir/4fd60181316c0cb257628528adb1c342.gif
The regex has a few issues:
^)*quantifier should be put after the group[].should be properly escaped so that it matches a literal period/ithere’s no need to specify botha-zandA-ZThe correct is:
See it in action.