Php regular expression matching nested <div> labels

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.