Php uses preg_match_all to match the image in the article

Source: Internet
Author: User
Tags php regular expression
Php uses preg_match_all to match the image in the article

  1. $ Con = file_get_contents ("http://bbs.it-home.org/news/jbxue-1.html ");
  2. $ Pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. jpg | \. png]) [\ '| \ "]. *? [\/]?> /";
  3. Preg_match_all ($ pattern, $ con, $ match );
  4. Print_r ($ match );
  5. ?>

Result: Array ([0] => Array ([0] => [1] => [2] =>) [1] => Array ([0] => http://bbs.it-home.org/usr/themes/dddefault/images/logo.png [1] => http://bbs.it-home.org/usr/uploads/2012/09/531656480.jpg [2] => http://bbs.it-home.org/usr/uploads/2012/09/2647136297.jpg ))

Articles you may be interested in: php code for matching image addresses: a PHP regular expression matching date and time (timestamp conversion) example php matches the regular expression of any Web site php regular expression rewrite html image img path code example PHP regular expression get URL domain name code use preg_replace function match image and add link method php the regular expression matches the domain name in the URL.

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.