记录一些常用的函数和瞎折腾的过程……

查找文章中的图片并输出

提醒:本文最后更新于 2383 天前,文中所描述的信息可能已发生改变,请谨慎使用。

这个函数的功能是查找文章中所有的图片,并按指定的最大数量输出这些已经查找到的图片:

// 所有图片
function all_img($soContent){
    $soImages = '~<img [^\>]*\ />~';
    preg_match_all( $soImages, $soContent, $thePics );
    $allPics = count($thePics);
    if( $allPics > 0 ){
        $count=0;
            foreach($thePics[0] as $v){
                 if( $count == 4 ){break;}
                 else {echo $v;}
                $count++;
            }
    }
}