The PHP regular expression is used to obtain the names of all images in the specified folder, and then delete these images.

Source: Internet
Author: User
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 );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.