function get_first_image(){
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches) || preg_match_all('/<object[0-9 a-z_?*=\":\-\/\.#\,<>\\n\\r\\t]+<\/object>/smi', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$mediaSearch = preg_match_all('/<object[0-9 a-z_?*=\":\-\/\.#\,<>\\n\\r\\t]+<\/object>/smi', $post->post_content, $matches2);
$first_media = $matches2 [1] [0];
$first_img = "/images/default.jpg";
}
if(!empty($first_img)){
$result = "<div class=\"alignleft\"><img src=\"$first_img\" style=\"max-width: 200px;\" /></div>";
}
if(!empty($first_media)){
$result = "<p>" . $first_media . "</p>";
}
return $result;
}
hi guys, i just wanted to ask what could be the mistake i am doing in this code. i am currently trying to find the first occurence of an image tag or an object tag then return a piece of html if it matches one. i can currently get the image tag done right. but unfortunately i cant seem to have any results on an object tag. i am thinking there maybe some mistake in my regex pattern or something. can you guys help me out? i hope i made it clear enough for you to understand thanks.