PHP 提取富文本中的全部图片(提取文章中的全部图片)
/*
PHP 提取富文本中的全部图片(提取文章中的全部图片)
* $content 文章内容
* $order 要获取哪张图片,ALL所有图片,0第一张图片
*/
function getImgs($content,$order='ALL')
{
$pattern ="/<img .*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$content,$match);
if(isset($match[1]) && !empty($match[1])){
if($order==='ALL'){
return $match[1];
}
if(is_numeric($order) && isset($match[1][$order])){
return $match[1][$order];
}
}
return [];
}
返回示例 array(2) { [0]=> string(66) "http://jb.mryxh.cn/wp-content/uploads/2022/09/Pasted-7-300x169.jpg" [1]=> string(66) "http://jb.mryxh.cn/wp-content/uploads/2022/09/Pasted-7-300x169.png" }
版权声明:
作者:admin
链接:http://blog.mryxh.cn/1265.html
文章版权归作者所有,未经允许请勿转载。
THE END