This article describes how to delete a picture when you modify the news in PHP. Share to everyone for your reference. The implementation methods are as follows:
?
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: The content of the announcement to be amended; $content: The revised announcement content $oldPic =array (); $nowPic =array (); Preg_match_all ("//", $old _contents, $match); if (!empty ($match [2])) {foreach ($match [2] as $key => $value) {Array_push ($oldPic, basename ($value));} Preg_match_ All ("//", $content, $testpic); if (!empty ($testpic [2])) {foreach ($testpic [2] as $key => $value) {Array_push ($nowPic, basename ($value));} $ Intersectpic=array_intersect ($nowPic, $oldPic);//Compute intersection foreach ($oldPic as $key => $value) {if!in_array ($value, $ Intersectpic)) {$delPic = "picture path". $value unlink ($delPic);} |
I hope this article will help you with your PHP program design.