PHP get images and div content instances in Web pages

Source: Internet
Author: User

The simple way to share the content of images and div in PHP is through regular expressions.

1. Get all the pictures in the webpage:

<?  //$text=file_get_contents(' http://www.jbxue.com/'//    preg_match_all $text $match/ /   Print_r($match?>

2. Get the first picture in the Web page:

<? PHP //  $text=file_get_contents(' http://www.jbxue.com/'//   Preg_match$text$match); // Print out Match Print_r ($match);? >

3. Gets the specific div chunk data for the specified page:

 <? php  //   $text  =file_get_contents  ('/HTTP/ www.jbxue.com/' );  //  remove line breaks and whitespace characters (required for serialization)//$text =str_ Replace (Array ("/R", "/n", "/t", "/S"), ", $text); Take out the DIV tag with id postcontent and store it in a two-dimensional array $match  preg_match  ('/<div[^& gt;] *id= "Postcontent" [^>]*> (. *) <//div>/si ',  $text ,  $match   //  print out match[0]  print  ( $match  [0? 

4. The above 2 and 3 are combined:

<?PHP//Obtain the content of the location and save it to the $text$text=file_get_contents(' http://www.jbxue.com/'); //Take out the div tag with id postcontent and store it in a two-dimensional array $matchPreg_match('/<div[^>]*id= ' Postcontent "[^>]*> (. *?) <//div>/si ',$text,$match); //gets the first IMG tag and stores it in a two-dimensional array $match 2Preg_match('/]*>/ui ',$text,$match 2); //print out match2[0]Print_r($match 2[0]); ?>

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.