Home >Backend Development >PHP Tutorial >How to regularly match divs with class in html and select the content in php, classdiv_PHP tutorial

How to regularly match divs with class in html and select the content in php, classdiv_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:401198browse

php regularly matches divs with class in html and selects the content, classdiv

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:

Copy code The code is as follows:



Tide tableThe data 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.

Copy code


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.

http://www.bkjia.com/PHPjc/942409.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/942409.htmlTechArticlephp regular matching method of div with class in html and selecting the content, classdiv This article describes the php regular matching How to create a div with class in html and select its content. Share with everyone...
Statement:
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