php - regexp to match all images without link -
this question has answer here:
i use regex match images. how can rewrite match images without </a>
in end ?
preg_match_all ("/\<img ([^>]*)\/*\>/i", $text, $dst);
soap box
i don't recommend using regex parse html string.
however
however might want try using dom first loop through images , store them in array.
foreach ($dom->getelementsbytagname('img') $img) { $array[$img->getattribue('src')]=1; }
then loop through links , try find image inside remove array.
foreach ($dom->getelementsbytagname('a') $a) { //loop catch multiple imgs in links foreach ($a->getelementsbytagname('img') $img) { unset($array[$img->getattribue('src')]); } }
Comments
Post a Comment