1, get all the pictures in the Web page:
Copy Code code as follows:
<?php
Gets the contents of the address and stores it in the $text
$text =file_get_contents (' http://www.jb51.net/');
Gets all the IMG tags and stores them in a two-dimensional array $match
Preg_match_all ('/]*>/i ', $text, $match);
Print out match
Print_r ($match);
?>
2, get the first picture of the Web page:
Copy Code code as follows:
<?php
Gets the contents of the address and stores it in 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. Get the specific div block data in the specified Web page:
Copy Code code as follows:
<?php
Gets the contents of the address and stores it in the $text
$text =file_get_contents (' http://www.jb51.net/');
Remove line break and white space characters (serialized content only needed to be used)
$text =str_replace (Array ("/R", "/n", "/t", "/S"), ", $text);
Remove the div tag and postcontent the contents of the ID, and save it to a two-dimensional array $match
Preg_match ('/<div[^>]*id= "Postcontent" [^>]*> (. *?) <//div>/si ', $text, $match);
Print out match[0]
Print ($match [0]);
?>
4. The integration of the above 2 and 3:
Copy Code code as follows:
<?php
Gets the contents of the address and stores it in the $text
$text =file_get_contents (' http://www.jb51.net/');
Remove the div tag and postcontent the contents of the ID, and save it to a two-dimensional array $match
Preg_match ('/<div[^>]*id= "Postcontent" [^>]*> (. *?) <//div>/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]);
?>