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; in the php regular expression matching webpage & lt; div & gt; tag & nbsp; to match with a specific id, obtain & nbsp; & lt; div & nbsp; & gt; & php regular expression matching nesting
Tag problems
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 repeat the php regular expression matching webpage.
To match tags with specific IDs,
Obtain
...
The regular expression used by the poster in this section is to judge
End
If p nesting occurs
In 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.