Regular matching nested div, PHP implementation

Source: Internet
Author: User
Regular Expression Matching nested div, evaluate PHP implementation ~ The following html string: $ str & nbsp; & lt; div & nbsp; & gt; & nbsp; & lt; div & nbsp; & gt; 1111111111 & lt; div & gt; & nbsp; & regular match nested p, evaluate PHP implementation ~
The following html string:
$ Str ='


1111111111


2222222222


Link1



1111111111



2222222222


';
Results to be matched:
Set

The content in is matched:
1 =>

1111111111


2222222222


Link1

2 =>

1111111111



2222222222


Php program implementation, online, etc ~

------ Solution --------------------
Reference:
$ Patten = '/(

(*)

)/';
Preg_match_all ($ patten, $ str, $ match );


It's not that simple, because there will be multiple

, You should start from the inner layer, and then layer by layer to know that

So Far
------ Solution --------------------
 $ Str ='


1111111111


2222222222


Link1



1111111111



2222222222


';
If (preg_match_all ('# ] *> (?> [^

] +
------ Solution --------------------
. +?
------ Solution --------------------

------ Solution --------------------
(? R ))*)

# Is ', $ str, $ matches )){
Print_r ($ matches );
}
?>

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.