PHP matches the class div in HTML and selects the contents of the method
This article mainly introduces the PHP regular matching in HTML with the class div and select the content of the method, involving the use of curl and regular matching skills, with a certain reference value, the need for friends can refer to the next
The example in this paper is a method that PHP matches the div in HTML with class and selects the content. Share to everyone for your reference. The specific analysis is as follows:
Let's take a look at some HTML code:
The code is as follows:
Tide TableData for reference only
Tide Time (Hrs) |
00:58 |
05:20 |
13:28 |
21:15 |
High tide (CM) |
161 |
75 |
288 |
127 |
Time zone:-1000 (East 10) Tidal height datum: 174CM at mean sea level
This is part of the source program, in order to be easy to understand, cut a large part, just take the contents of the DIV block
Home first Use file_get_content or curl to get the content part, 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);
$regex 4= "/.*?<\/div>/ism";
if (Preg_match_all ($regex 4, $return, $matches)) {
Print_r ($matches);
}else{
echo ' 0 ';
}
This is OK, not much explanation, understand the PHP code, print to see the effect.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/971923.html www.bkjia.com true http://www.bkjia.com/PHPjc/971923.html techarticle PHP matches the class div in HTML and selects the contents of the method this article mainly introduces the PHP regular matching in HTML with the class div and select the content of the method, involving the use of curl and ...