Possible Duplicate:
Retrieve 1st image in post and set it as featured image, when post is saved/updated
我正在努力使这项工作,它不是给我图像的url,而是给我“数组”
我有一段代码,可以获取帖子的第一张图片
// 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;
}
此代码用于显示图像:
<img src="<?php echo catch_that_image() ?>" width="608" height="250" />
你能告诉我我做错了什么以及如何修复它吗?非常感谢。