Php regular expression matching nesting & lt; div & gt; tag issues new php, & nbsp; recently used php to write regular expression matching & nbsp; encountered a problem; preg_match & nbsp; function & nbsp; when the php regular expression matching webpage & lt; div & gt; tag & nbsp; wants to match with a specific id, php regular expression matching nested tags
A beginner in php who recently encountered a problem in writing regular expression matching in php
The main user uses the preg_match function to match webpage tags with specific IDs in php regular expressions,
That is, get... the regular expression used by the main user in this section is used to determine that the expression ends.
In this case, if you encounter div nesting
The first tag ends.
How can I solve this problem in php ?..
Or is there a function or library that can get all the content in the tag by tag id?
The landlord hopes that php has functions or libraries that can get the entire tag content at once instead of manual regular expressions. python and java are usually used more often and are relatively lazy ..
I am not familiar with php. I am not very grateful if I can recommend some good learning websites.
------ Solution --------------------
$ S = <TXT
TXT;
$ S = iconv ('gbk', 'utf-8', $ s); // no need for UTF-8
Require ('phpquery. php ');
$ Doc = phpQuery: newDocument ($ s );
// Echo $ doc-> find ('# tid')-> html (); // you can write
Echo pq ('# tid')-> html (); // You can also write
You can also use regular expressions, but every time you have to stick your brains, it is a little less than worth the candle
With the phpQuery class, you only need to use js jQuery.