Home > php教程 > php手册 > 删除文章中的图片

删除文章中的图片

WBOY
Release: 2016-06-07 11:37:56
Original
1878 people have browsed it

我在用百度的ueditor进行文章编辑时会上传图片到服务器,做删除文章这一功能的时候想了一下怎么样把文章中的图片也删除掉,下面就是我的做法,权当做一个笔记,代码写的很差,毕竟是新手,欢迎高人指点
$article    = M('Article');<br> $content = $article->where('id="'.$_GET['id'].'"')->getField('content');<br> $img_arr = array();<br> //$regex = '/img src="\/(.*?)"/i';//只删除本地图片<br> $regex = '/img\s+src=['\"]\/{1}(.*?)['\"]/';<br> preg_match_all($regex,$content,$img_arr);<br>         $img_arr = $img_arr[1];<br> for($i=0;$i<sizeof></sizeof>             if(!unlink('./'.$img_arr[$i])){<br>                 die('删除文章中的图片失败!');<br>             }<br>         }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template