一聚教程网:一个值得你收藏的教程网站

热门教程

php正则获取文章内容中图片地址例子

时间:2022-06-25 02:40:27 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码


例子

function getpic($str){
 preg_match_all("//isU",$str,$ereg);//正则表达式把图片的整个都获取出来了 
    $img=$ereg[0][0];//图片
    $p="#src=('|\")(.*)('|\")#isU";//正则表达式
    preg_match_all ($p, $img, $img1); 
    $img_path =$img1[2][0];//获取第一张图片路径
// print_r($img_path);  
    return $img_path; 
}
 
$imgs=getpic($row['post_content']);
$row['post_content'] //获取数据库里面的文章的内容。

热门栏目