用于在博客文章上获取第二张图片的PHP代码
|
我正在使用以下代码来从博客文章中获取图片:
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];
if(empty($first_img)){ //Defines a default image
$first_img = \"/images/default.jpg\";
}
return $first_img;
}
现在,我需要一些帮助来进行较小的修改。这是我要查找的内容:我希望代码忽略第一个图像,抓取它找到的第二个图像,如果找不到第二个图像,则使用默认图像(后备图像)。
没有找到相关结果
已邀请:
2 个回复
淑灯
导力疵谜
这里的窍门是使用
和
参数1来删除第一张图像。