Php: getting images and DIV content from webpages _ PHP Tutorial

Source: Internet
Author: User
Php retrieves images and DIV content instances from webpages. A simple method for php to retrieve images and DIV content on a webpage is implemented through regular expressions. 1. get all the images on the webpage :? Php obtains the content of a specified address, and saves and shares the simple method of php getting images and DIV content on a webpage, which is implemented through regular expressions.

1. retrieve all images on the webpage:

 /I ', $ text, $ match); // Print the match print_r ($ match);?>

2. obtain the first image on the webpage:

 /Ui ', $ text, $ match); // Print out matchprint_r ($ match);?>

3. obtain the specific p block data on the specified webpage:

 ] * Id = "PostContent" [^>] *> (.*?)
 /Si', $ text, $ match); // print the match [0] print ($ match [0]);?>

4. The combination of the above 2 and 3:

 ] * Id = "PostContent" [^>] *> (.*?)
 /Si', $ text, $ match); // obtain the first img tag and store it in a two-dimensional array $ match2 preg_match ('/] *>/Ui ', $ text, $ match2); // Print out match2 [0] print_r ($ match2 [0]);?>

Bytes. 1. get all the images on the webpage :? Php // Obtain the content of the specified address and store it...

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.