/*删除文章内容图片(也就是删除编辑器上传的图片)*/
function delete_img($content){
//匹配并删除图片
$img_path = "/<img.*src=\"([^\"]+)\"/U";
$matches = array();
preg_match_all($img_path, $content, $matches);
foreach($matches[1] as $img_url){
//strpos(a,b) 匹配a字符串中是否包含b字符串 包含返回true
if(strpos($img_url, 'emoticons')===false){
$host = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$filepath = str_replace($host,'',$img_url);
if($filepath == $img_url) $filepath = substr($img_url, 1);
@unlink($filepath);
$filedir = dirname($filepath);
$files = scandir($filedir);
if(count($files)<=2)@rmdir($filedir);//如果是./和../,直接删除文件夹
}
}
unset($matches);
}
thinkphp删除文章里的所有图片
最新推荐文章于 2022-03-31 11:30:51 发布