Ask the PHP regular expression to get the names of all the images in the specified folder, and then delete these images. Recently, I helped my friends to make a background, which uses fckeditor as the editor, however, fckeditor does not provide the function of writing Image names to the database after uploading images. only data is deleted when news is deleted, and images in news are still stored on the server, which will accumulate a lot of junk images in the future. PHP regular expressions are used to obtain the names of all images in the specified folder, and then delete these images.
Recently, I made a background for my friends. fckeditor is used as the editor, but fckeditor does not provide the function to write image names to the database after uploading images. only data is deleted when news is deleted, the pictures in the news are still on the server, which will accumulate a lot of junk pictures in the future. therefore, when you delete an image, you want to read the relevant images in the upimages folder in the news content and then delete it.
For example, there are 4 picture links in my news
Ask the experts about how to write regular expressions and the code to delete the image after obtaining the image name. thank you !!!!
------ Solution --------------------
Just like this...
PHP code
$ News_content = ''; if (preg_match_all (" // ", $ news_content, $ getvalues) {foreach ($ getvalues [1] as $ filename) {unlink ('upimages /'. $ filename );}}