How to extract image names with php or regex -
i have following data in mysql.
<p><img src="../../../../assets/images/frontpage/image1.png" alt="" width="790" height="356" /></p> now want image2.png php or regex. extension can gif or jpg. , length of image name can length.
how can it.
thanks help.
this match path in img tag , capture file in first interior capturing group.
<?php if (preg_match('%<img\s.*?src=".*?/?([^/]+?(\.gif|\.png|\.jpg))"%s', $subject, $regs)) { $image = $regs[1]; } else { $image = ""; } ?>
Comments
Post a Comment