Php regular expressions are equipped with div blocks. how can this problem be solved?

Source: Internet
Author: User
php regular equipped with div block
$a='<divid="css">1<div>2</div>3</div><div>4</div>';preg_match_all('/
php regular equipped with div block


$a='1234';

preg_match_all('/(.*?)<\/div>/',$a,$match);
echo '
';
var_dump ($ match);

I would like to ask experts: all matching divs written on the Internet are written like this, but when I wrote, I found that he could not completely match a div block! Such as this, my div id = css, his end / div is behind 3, but this can only be written to 2, and it ends. Is there any way to match his own div block?

------solution--------------------
http://downloads.sourceforge.net/project/simplehtmldom/simplehtmldom/1.5/simplehtmldom_1_5.zip?r=http://sourceforge.net/projects/simplehtmldom/files/&ts=1332749181&use_mirror=nchc

simplehtmldom class
Simple, practical and efficient

No need to fiddle with the rules at all

------solution--------------------

Nested tags are matched recursively
PHP code
(([^ <>] * | (? R)) *)] *> # ';
preg_match_all ($ pattern, $ str, $ matches);

echo $ matches [0] [0];
// 123

------solution--------------------
Explore

Um, what's the solution? If it's a page of code, we want to remove the head and tail divs. Is there any good solution? 

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.