/*删除文章内容图片(也就是删除编辑器上传的图片)*/
function remove_content_img($content){
//匹配并删除图片
$imgreg = "/<img.*src=\"([^\"]+)\"/U";
$matches = array();
preg_match_all($imgreg, $content, $matches);
foreach($matches[1] as $img_url){
if(strpos($img_url, 'emoticons')===false){
$web_root = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$filepath = str_replace($web_root,'',$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);
} 最佳答案