Php regular expression matches the div with class in html and selects the method of the content _ PHP Tutorial

Source: Internet
Author: User
Tags php regular expression
Php regular expression matches the div with class in html and selects the content method. Php regular expression matching: div with class in html and content selection method this article mainly introduces php regular expression matching: div with class in html and content selection method, the method that involves curl usage and php regular expression matching of p with class in html and selection of content

This article mainly introduces the php regular expression matching html with class p and selects the content method, which involves the use of curl and regular expression matching techniques. it has some reference value, for more information, see

This example describes how to use php regular expression to match the class p in html and select the content. 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.

This article mainly introduces the php regular expression matching of p with class in html and the method of selecting the content, which involves the use of curl and...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.