PHP uses regular expressions to replace the src content in Img in batches to obtain thumbnails.
This example describes how PHP can obtain thumbnails by replacing the src content in Img in batches based on regular expressions. We will share this with you for your reference. The details are as follows:
Here, PHP uses regular expressions to replace the src content in Img in batches to obtain image path thumbnails.
Many regular expressions on the internet can only get or replace the src content of one img, or can only replace fixed strings. It takes several hours to dynamically Replace the content of multiple images.
/*** Replace the image address with the compressed URL * @ param string $ content * @ param string $ suffix */function get_img_thumb_url ($ content = "", $ suffix = "! C550x260.jpg ") {$ pregRule ="/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Jpg | \. jpeg | \. png | \. gif | \. bmp]) [\ '| \ "]. *? [\/]?> /"; $ Content = preg_replace ($ pregRule, '', $ content); return $ content ;}
Sample Code:
$content = '<a href="#" rel="external nofollow" rel="external nofollow" ></a>'.'<p></p>';$newct = get_img_thumb_url($content);print_r($newct);
Output result:
Copy codeThe Code is as follows: <a href = "#" rel = "external nofollow" rel = "external nofollow"> </a> <p> </p>
PS: here we will provide two very convenient Regular Expression tools for your reference:
JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript
Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg