Use the Preg_replace function to match a picture and add a linked method

Source: Internet
Author: User
Tags php regular expression
  1. $con = file_get_contents ("http://bbs.it-home.org/wzjs/");
  2. $pattern = "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/];
  3. $new _con = preg_replace ($pattern, "$", $con);
  4. echo $new _con;
  5. ?>
Copy Code

Description: $ A matches the match, which means that the first () matches the contents of the second () match, and so on! In this way to add links to the picture, interested friends may wish to do their own tests under OH.

you may be interested in the article:PHP matches the image address of the code in a case of PHP regular match date and time (timestamp conversion) Example PHP matches the regular expression of any URL php regular match rewrite HTML image img Path code example PHP regular match gets the URL of the domain name code PHP with Preg_match_all matches the picture in the article PHP regular expression matches the domain name in the URL

  • Related Article

    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.