PHP Regular expression extract image URL program

Source: Internet
Author: User
Tags array sort php regular expression
Use the regular expression to get the IMG tag, and then extract each img tag src, and combine it into its own content, and finally replace

I want to extract the images of HTML.

As above address. I want to extract it all but the address that contains ' ico ' is ignored. To ask for a regular, is some picture extraction. Some do not extract.

Example:

<s*imgs+[^>]*?srcs*=s* (' | ') (.*?) \1[^>]*?/?s*>

After improvement:

The correct answer is as follows

//

Instance

Content to replace $content = ' <br><br><br><br> ";//extract the image path of the SRC regular expression preg_match_all ("/]+>/isu ", $content, $matches); $img =" ", if (!empty ($matches)) {//note, the above regular expression indicates that the value of SRC is placed in the third of the array $img = $matches [2] ;} else {$img = "";} if (!empty ($img)) {$img _url = "http://". $_server[' server_name '); $patterns = Array (); $replacements = Array (); foreach ($ IMG as $imgItem) {$final _imgurl = $img _url $imgItem; $replacements [] = $final _imgurl; $img _new = "/". Preg_replace ("///i", "/", $imgItem). " /"; $patterns [] = $img _new;} Let the array sort by key ksort ($patterns); Ksort ($replacements);//replace content $vote_content = Preg_replace ($patterns, $replacements, $ content);

Related articles:

PHP Regular Expression extract HTML tag problem

Sample PHP code for extracting HTML tags

Extracting HTML tags from PHP

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