Answer the question
In order to leave comments, you need to log in
How to write a regular expression for preg_match_all so that it doesn't cut the closing div?
How to write a regular expression with a check that if there is a nested div, then we skip both the opening and closing divs.
$content = '<div class="zzz">wwwww<div>zzz</div>yyy<div>qqqq</div>ppp</div>';
$pattern = "|<div class=\"zzz\">(.+?)<\/div>|";
$text = preg_match_all($pattern, $content, $return);
echo $return[1][0];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question