1. Get all the pictures in the webpage:
Copy CodeThe code is as follows:
<?php
Obtain the content of the location and save it to the $text
$text =file_get_contents (' http://www.jb51.net/');
Get all IMG tags and store them in a two-dimensional array $match
Preg_match_all ('/]*>/i ', $text, $match);
Print out match
Print_r ($match);
?>
2. Get the first picture in the Web page:
Copy the Code code as follows:
<?php
Obtain the content of the location and save it to the $text
$text =file_get_contents (' http://www.jb51.net/');
Gets the first IMG tag and stores it in a two-dimensional array $match
Preg_match ('/]*>/ui ', $text, $match);
Print out match
Print_r ($match);
?>
3. Gets the specific div chunk data for the specified page:
Copy the Code code as follows:
<?php
Obtain the content of the location and save it to the $text
$text =file_get_contents (' http://www.jb51.net/');
Remove line breaks and white space characters (required for serialization of content)
$text =str_replace ("/R", "/n", "/t", "/S"), ",", $text);
Take out the DIV tag with id postcontent and store it in a two-dimensional array $match
Preg_match ('/]*id= ' postcontent ' [^>]*> (. *?) /si ', $text, $match);
Print out match[0]
Print ($match [0]);
?>
4. The above 2 and 3 are combined:
Copy the Code code as follows:
<?php
Obtain the content of the location and save it to the $text
$text =file_get_contents (' http://www.jb51.net/');
Take out the DIV tag with id postcontent and store it in a two-dimensional array $match
Preg_match ('/]*id= ' postcontent ' [^>]*> (. *?) /si ', $text, $match);
Gets the first IMG tag and stores it in a two-dimensional array $match 2
Preg_match ('/]*>/ui ', $text, $match 2);
Print out match2[0]
Print_r ($match 2[0]);
?>
http://www.bkjia.com/PHPjc/825379.html www.bkjia.com true http://www.bkjia.com/PHPjc/825379.html techarticle 1. Get all the pictures on the webpage: Copy the Code code as follows: PHP//Obtain the content of the location, and save to $text $text =file_get_contents (' http://www.jb51.net/');//Get all ...