Possible Duplicate:
Retrieve 1st image in post and set it as featured image, when post is saved/updated
I am trying to make this works and instead of giving me the url of the image, it is giving me "Array"
I have this code that gets the first image of the post
// Get URL of first image in a post
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
// no image found display default image instead
if(empty($first_img)){
$first_img = "/images/default.jpg";
}
$first_img = vt_resize( $first_img, '', 608, 250, true );
return $first_img;
}
and this code to display the image:
<img src="<?php echo catch_that_image() ?>" width="608" height="250" />
Could you please tell me what I am doing wrong and how to fix it please? Thank you.