This article describes how to delete an image when modifying news in php, and related skills related to php regular expression replacement, for more information about how to delete an image when using php to modify news, see the following example. Share it with you for your reference. The specific implementation method is as follows:
// Old_contents: the announcement to be modified; // $ content: the modified 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); // calculate the intersection foreach ($ oldPic as $ key => $ value) {if (! In_array ($ value, $ intersectPic) {$ delPic = "Image path". $ value unlink ($ delPic );}}
I hope this article will help you with php programming.