Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use php to regularly match div with class in html and select its contents

Shulou Source: shulou.com Published: 2022-06-03 19:06:52 11月12日 Update

This article mainly introduces "how php uses regular matching div with class in html and selects contents". In daily operation, it is believed that many people have doubts about how to use regular matching div with class in html and select its content. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the question of "how to use php to regularly match the div with class in html and select the content in it"! Next, please follow the editor to study!

This paper gives an example of how php regularizes the div with class in html and selects its contents. Share it with you for your reference. The specific analysis is as follows:

Let's first look at a piece of html code:

The copy code is as follows:

Tide table data are for reference only

Tide time (Hrs)

00:58

05:20

13:28

21:15

Tide height (cm)

one hundred and sixty one

seventy-five

two hundred and eighty eight

one hundred and twenty seven

Time zone:-1000 (East 10) Tidal height Datum: 174CM below mean sea level

This is a part of the source program. In order to make it easy to understand, a large part is deleted, only the contents of the div block are taken.

The home page first uses file_get_content or curl to get the content part, I use curl.

The copy 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'

}

This is fine, without much explanation, understand the PHP look at the code, print to see the effect.

At this point, the study on "how to use php to regularly match the div with class in html and select the content" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Content code regular median learning method more part help practical for reference only next benchmark example effect data article time zone sea level source program Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL vpn Shulou Technology macOS