PHP, preg_match, select part of many div tags
so i need to take the whole div with class "1" but it stops at the div class "1.1" ending so i want to get from this:
<head>
</head>
<body>
<div class="1">
<p>blah blah blah</p>
<div class="1.1">
trolololol
</div>
<div class="1.2">
trolo2lolo
</div>
</开发者_运维问答div>
</body>
only this:
<div class="1">
<p>blah blah blah</p>
<div class="1.1">
trolololol
</div>
<div class="1.2">
trolo2lolo
</div>
</div>
but for now i get only:
<div class="1">
<p>blah blah blah</p>
<div class="1.1">
trolololol
</div>
Regexp are not that intelligent to count how many tags you have opened and need to be closed before stopping the match. It stops at the first occurence of </div>
. Try to use a real html parser if you want to access tags as real tags and not strings.
Regular expressions should not be used to parse documents like XML, HTML, "BBCode", JSON... You should look for a real DOM parser, for example PHP's DOM extension
精彩评论