Home > Article > Backend Development > How to use php to process images in articles
The above uses regular expressions. Explain: first match the four letters of http Then match several non-digit characters. Match at least one numeric character, match one dot (.), and search for the match ending with jpg or gif or png from $congtent. The result is stored in $temp. Save the images in the original data in the database in an array named $oldimgs. This needs improvement. After saving, it prints out a two-dimensional array, which is a bit cumbersome to use. Explanation, my picture name is similar to this: "201111291322589013.jpg" Step 2: The method to find all the images from the content submitted by the user is as above. The second array is obtained and named $newimgs The method to find the difference set between arr1 and arr2 is as follows --That is to say, if the picture in the original data does not exist in the user's newly submitted content, then the picture will be deleted.
Delete pictures:
When a user edits an article with a picture. If the picture is deleted, the corresponding picture will also be deleted from the website. The method of getting the name of the picture in the article can also be applied to the process of deleting the article. In the method of deleting pictures, you can use realpath(__FILE__) plus various "./" "../" to $dir to give the picture directory relative to the website directory. |