preg_match_all exclude .gif extension


preg_match_all exclude .gif extension

我在一个网站上工作,我已经设置好从wordpress帖子中获得第一个和第二个图像,用作自定义主页布局。

我使用的是这个代码:

//GET FIRST IMAGE ON POST
function get_first_image($size = false) {
    global $post, $_wp_additional_image_sizes;
    $first_img = '';
    $output = preg_match_all('/<img.+src=[''"]([^''"]+)[''"].*>/i', $post->post_content, $matches);
    $first_img = $matches[1][0];
    if (empty($first_img)) {
        return;
    }
    if ($size && $_wp_additional_image_sizes[$size]['crop'] == 1) {
        $size = '-' . $_wp_additional_image_sizes[$size]['width'] . 'x' . $_wp_additional_image_sizes[$size]['height'] . '.jpg';
        $pattern = '/-'d+x'd+'.jpg$/i';
        $first_img = preg_replace($pattern, $size, $first_img);
    }
    return $first_img;
}

我的问题是,我的客户在她的博客中使用JPG图片,但也有一些。文章中的GIF图片,这些。我想跳过GIF,只有当图片是有效的时才能获得。JPG图像,我该怎么做?

此正则表达式将包括jp(e)g和png,因此不包括gif。

<img's.*src='?".+(jpe?g|png).+>