Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report