Codice PHP:
preg_match("/<img[^>]+>/"$var$match);
echo 
htmlentities($match[0]);