1. Get all the pictures in the webpage:
Copy code The code is as follows:
//Get the content of the specified address and save it to $text
$text=file_get_contents('http://www.jb51.net/');
//Get all img tags and store them in the two-dimensional array $match
preg_match_all('/
]*>/i', $text, $match);
//Print out match
print_r($match);
?>
2. Get the first picture in the webpage:
Copy code The code is as follows:
//Get the content of the specified address and save it to $text
$text=file_get_contents('http://www.jb51.net/');
//Get the first img tag and store it in the two-dimensional array $match
preg_match('/]*>/Ui', $text, $match);
//Print out match
print_r($match);
?>
3. Get specific div block data in the specified web page:
Copy code The code is as follows:
//Get the content of the specified address and save it to $text
$text=file_get_contents('http://www.jb51.net/');
//Remove newlines and whitespace characters (required for serialized content)
//$text=str_replace(array("/r","/n","/t","/s"), '', $text);
//Get the content of the div tag with the id PostContent and store it in the two-dimensional array $match
preg_match('/
]*id="PostContent"[^>]*>(.*?) /div>/si',$text,$match);
//Print out match[0]
print($match[0]);
?>
4. Combination of 2 and 3 above:
Copy code The code is as follows:
//Get the content of the specified address and save it to $text
$text=file_get_contents('http://www.jb51.net/');
//Take out the content of the div tag with the id PostContent and store it in the two-dimensional array $match
preg_match('/
]*id="PostContent"[^>]*>(.*?) /div>/si',$text,$match);
//Get the first img tag and store it in the two-dimensional array $match2
preg_match('/
]*>/Ui', $text, $match2);
//Print out match2[0]
print_r($match2[0]);
?>
http://www.bkjia.com/PHPjc/825379.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825379.htmlTechArticle1. Get all the pictures in the webpage: Copy the code as follows: php //Get the content of the specified address, And save to $text $text=file_get_contents('http://www.jb51.net/'); //Get all...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31