I have a little coding I need help with and hope somebody can lend assistance. Here is what I am trying to do, currently this works very well but I need to not replace any image tag that has an alt tag in it. Thanks. preg_replace( "#<img(?:.+?)src=[\"'](\S+?)['\"][^>]+?>#is", "image holder", $comment );
Maybe something like this? function replaceNotAlt ($alt){ if (preg_match('#alt\s*=\s*([\'"])[^>]+\1#', $alt[0], $matches) ) { return $alt[0]; } else { // return what you want here } } $text = preg_replace_callback('#<img[^>]+?>#is', "replaceNotAlt", $text ); PHP: