Regex and PHP for extracting contents between tags with several line breaks

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-06-10T04:45:04Z Indexed on 2010/06/10 5:02 UTC
Read the original article Hit count: 445

Filed under:
|
|

How can I extract the content between tags with several line breaks?

I'm a newbie to regex, who would like to know how to handle unknown numbers of line break to match my query.

Task: Extract content between <div class="test"> and the first closing </div> tag.

Original source:

<div class="test">optional text<br/>
content<br/>
<br/>
content<br/>
...
content<br/><a href="/url/">Hyperlink</a></div></div></div>

I've worked out the below regex,

/<div class=\"test\">(.*?)<br\/>(.*?)<\/div>/

Just wonder how to match several line breaks using regex.

There is DOM for us but I am not familiar with that.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex