This article mainly introduces the php regular expression matching html div with class and selects the content method, which involves the use of curl and regular expression matching techniques. it has some reference value, for more information about php regular expression matching, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
First look at the html code:
The code is as follows:
Tide tableData is for reference only
Hrs) |
00:58 |
05:20 |
13: 28 |
|
High tide (cm) |
161 |
75 |
288 |
127 |
Time zone:-1000 (East 10) tidal high reference: 174 at average sea level
This is a part of the source program. in order to make it easy to understand, a large part of the program is deleted.
Content in Block p
On the homepage, use file_get_content or curl to obtain the content. 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 = "/
.*? <\/P>/ism ";
If (preg_match_all ($ regex4, $ return, $ matches )){
Print_r ($ matches );
} Else {
Echo '0 ';
}
In this way, you can understand PHP code and print the results.
I hope this article will help you with php programming.