Archives
function mbmCountImg($txt = ”){ preg_match_all(‘/<img[^>]+>/i’,$txt, $result); //select img tags $img = array(); foreach( $result as $kk=>$v) { foreach( $result[$kk] as $k=>$vv) { preg_match_all(‘/(alt|title|src)=(“[^"]*”)/i’,$vv, $img[$k]); //images into arrays } } return count($img); //counting total arrays } Usage: $content .= ”; $content .= ”; $content .= ”; $content .= ”; echo mbmCountImg($content);
Aug 15th, 2009 | Filed under PHP
Tags: count images, PHP