本文实例讲述了php实现修改新闻时删除图片的方法。分享给大家供大家参考。具体实现方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//old_contents:待修改的公告内容; //$content:修改后的公告内容 $oldPic = array (); $nowPic = array (); preg_match_all( "/\<IMG(.*?)src=\"(.*?)\">/" , $old_contents , $match ); if (! empty ( $match [2])){ foreach ( $match [2] as $key => $value ){ array_push ( $oldPic , basename ( $value )); } } preg_match_all( "/\<IMG(.*?)src=\"(.*?)\">/" , $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 ); } } |
希望本文所述对大家的php程序设计有所帮助。