我需要从帖子中提取第一张图片,我找到了这段代码,但这显示了帖子中的最后一张图片(例如:http: //zonadictoz.com.ar),我不知道为什么!
function myPostImage()
{
  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];
  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}
有任何想法吗?