0

Example: https://regex101.com/r/nHiyU3/1

CODE:

<div id="content">
    <div>
        <div class="col-image"></div> <!-- STOPS HERE -->
        THIS CONTENT HERE DOES NOT GET CAPTURED
    </div>
</div>

REGEX:

/<div id=[\'|"]content[\'|"][^>]*>(.*)<\/div>/sUi

So it stops where I've added the note to say

Any reason why? Have followed other topics on SO but can't get it to grab the whole lot.

So I know how to do it across multiple lines, it's finding the matching tag across multiple lines

3

1 Answer 1

1

As mentioned in the comments, it's easier to achieve this using DOMDocument. For example:

<?php
    $html = '<div id="content"><div><div class="col-image"></div> <!--
             STOPS HERE -->THIS CONTENT HERE DOES NOT GET CAPTURED</div></div>';
    $domDocument = DOMDocument::loadHTML($html);
    $divList = $domDocument->getElementsByTagName('div');
    foreach ($divList as $div) {
        var_dump($div);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.