Home > Backend Development > PHP Tutorial > How to regularly match divs with classes in html and select their contents_PHP Tutorial

How to regularly match divs with classes in html and select their contents_PHP Tutorial

WBOY
Release: 2016-07-13 10:01:34
Original
1004 people have browsed it

How to match divs with class in html using php and select the content

This article mainly introduces how php can match divs with class in html and select the content. The method involves the use of curl and regular matching skills, which has certain reference value. Friends in need can refer to it

The example in this article describes the method of php regularly matching divs with classes in html and selecting the content. Share it with everyone for your reference. The specific analysis is as follows:

Look at a piece of html code first:

The code is as follows:




Tide tableData is for reference only















Tide Time (Hrs)

00:58

05:20

13:28

21:15

Tide height (cm)

161

75

288

127


Time zone: -1000 (East 10th District) Tide height datum: 174CM below mean sea level





This is part of the source program. In order to make it easier to understand, a large part has been deleted. Only the content in the

div block is taken

First use file_get_content or curl to get the content part on the home page. I use curl.

The code is as follows:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$return = curl_exec( $ch );
curl_close( $ch );

$regex4="/
.*?
/ism";
if(preg_match_all($regex4, $return, $matches)){
print_r($matches);
}else{
echo '0';
}

That’s it, no explanation required. If you know PHP, read the code and print it to see the effect.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971923.htmlTechArticlephp regular matching method of div with class in html and selecting the content. This article mainly introduces php regular matching How to select a div with class in html and select its content, involving the use of curl and...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template