Use Preg_match_all in PHP to match pictures _php instances in an article

Source: Internet
Author: User
Preg_match_all function:

int Preg_match_all (string pattern, string subject, array matches [, int flags]) performs a global regular expression match
Searches in subject for all content that matches the regular expression given by the pattern and places the result in matches in the order specified by flags.
After the first match is searched, the next search starts at the end of the previous match.
Flags can be a combination of the following tags (note that it makes no sense to combine Preg_pattern_order and Preg_set_order):
Preg_pattern_order The result sort so that $matches [0] is an array of all pattern matches, $matches [1] is an array of strings that match the sub-patterns in the first parenthesis, and so on!

Example:

Copy the Code code as follows:
$con = file_get_contents ("http://www.php.net/news/jb-1.html");
$pattern = "/<[img| Img].*?src=[\ ' |\ "] (. *? (?: [\.gif|\.jpg|\.png])) [\ ' |\ '].*? [\/]?>/];
Preg_match_all ($pattern, $con, $match);
Print_r ($match);
?>

Results:
Copy the Code code as follows:
Array
(
[0] = = Array
(
[0] = =
[1] = =
[2] = =
)
[1] = = Array
(
[0] = Http://www.php.net/usr/themes/dddefault/images/logo.png
[1] = Http://www.php.net/usr/uploads/2012/09/531656480.jpg
[2] = Http://www.php.net/usr/uploads/2012/09/2647136297.jpg
)
)

  • 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.