Home > Backend Development > PHP Tutorial > PHP method to delete pictures when modifying news, _PHP tutorial

PHP method to delete pictures when modifying news, _PHP tutorial

WBOY
Release: 2016-07-13 09:54:12
Original
836 people have browsed it

php implements the method of deleting pictures when modifying news,

This article describes the example of php implementing the method of deleting pictures when modifying news. Share it with everyone for your reference. The specific implementation method is as follows:

//old_contents:待修改的公告内容;
//$content:修改后的公告内容
$oldPic=array();
$nowPic=array();
preg_match_all("/\<IMG(.*&#63;)src=\"(.*&#63;)\">/",$old_contents,$match);
if(!empty($match[2])){
 foreach($match[2] as $key=>$value){
 array_push($oldPic,basename($value));
 }
}
preg_match_all("/\<IMG(.*&#63;)src=\"(.*&#63;)\">/",$content,$testpic);
if(!empty($testpic[2])){
 foreach($testpic[2] as $key=>$value){
 array_push($nowPic,basename($value));
 }
}
$intersectPic=array_intersect($nowPic,$oldPic);//计算交集
foreach($oldPic as $key=>$value){
 if(!in_array($value,$intersectPic)){
 $delPic="图片路径".$value
  unlink($delPic);
 }
}
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/998552.htmlTechArticlephp implements the method of deleting pictures when modifying news. This article describes the method of deleting pictures when modifying news in php. Share it with everyone for your reference. The specific implementation method is as follows: /...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template