PHP based on regular bulk replacement img In the SRC content to achieve the function code to get thumbnails

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

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.