In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use PHP regular expression to grab the specific attribute value of a tag". In daily operation, it is believed that many people have doubts about how to use PHP regular expression to grab the specific attribute value of a tag. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the question of "how to use PHP regular expressions to grab a specific attribute value of a tag"! Next, please follow the editor to study!
Php learned regularization for a few days, grabbed some website data, and found it troublesome to write regularities every time, so he wanted to write an interface that crawls specific tags with specific attribute values, directly on the code.
/ / $html- searched string $tag- looked up tag $attr- looked up attribute name $value- looked up attribute value function get_tag_data ($html,$tag,$attr,$value) {$regex = "/ (. *?) / is"; echo $regex. "
"; preg_match_all ($regex,$html,$matches,PREG_PATTERN_ORDER); return $matches [1];} / / the return value is the contents of the tags found in the array
Here's a random example.
Header ("Content-type: text/html; charset=utf-8"); $temp = 'Home blog LOFTER photo album about me'; $result = get_tag_data ($temp, "a", "class", "fc01"); var_dump ($result)
The output is
Array (6) {[0] = > string (6) "Home" [1] = > string (6) "Log" [2] = > string (6) "LOFTER" [3] = > string (6) "Photo album" [4] = > string (6) "Boyou" [5] = > string (9) "about me"}
If you view the source code, you can see
Array (6) {[0] = > string (6) "Home" [1] = > string (6) "Log" [2] = > string (6) "LOFTER" [3] = > string (6) "Photo album" [4] = > string (6) "Bo you" [5] = > string (9) "about me"} this is the end of the study on "how to use PHP regular expression to grab a specific attribute value of a tag". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.