This article mainly introduces PHP based on the regular batch replacement img In the SRC content to achieve the function of thumbnail, involving PHP for the page IMG elements of the regular matching and replacement operations related implementation skills, the need for friends can refer to the following
In this paper, we describe the function of PHP to obtain thumbnails based on the SRC content in regular bulk substitution img. Share to everyone for your reference, as follows:
Here PHP with regular batch replacement img In the SRC content, to obtain the image path thumbnail function
Many regular expressions on the Web can only retrieve or replace an IMG src content, or can only replace a fixed string, to dynamically replace the contents of multiple images for several hours to solve.
/*** picture address is replaced with compressed url* @param string $content content * @param string $suffix 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;}
Instance Usage code:
$content = ' <a href= ' # "rel=" external nofollow "rel=" external nofollow "></a>". <p></p> '; $newct = Get_img_thumb_url ($content);p rint_r ($NEWCT);
Output Result:
The code is as follows:
<a href= "#" rel= "external nofollow" rel= "external nofollow" ></a><p></p>