Regular expression php: Find everything in DIV

I am trying to use regexp to find eveything in a div. I know there may be a smarter way – but I chose regexp.

So currently My regular expression pattern is as follows:

$gallery_pattern ='/

It’s a bit tricky.

The problem is if I have two divs-like this.


I want to extract from two divs Information, but my problem during the test is that I didn’t get the result between the text, but:

"text to extract here 

< div class="gallery">text to extract from here as well"

So to summarize. It will skip the first end of the div. And continue to the next one.
The text in the div can contain <,/ and line break. Just you know! Does anyone have a simple solution to this problem? I am still a novice in regular expressions.

how about something like this:

$str = <<text to extract here

HTML;$matches = array();preg_match_all('#]*>(.*?)
#', $str, $matches);var_dump($ matches[1]);

Attention’? ‘In the regular expression, so it is “not greedy”.

Which will give you:

array
0 => string ' text to extract here' (length=20)
1 => string'text to extract from here as well' (length=33)

This should work fine…if you don’t have a tile Fragmented div; if you do this…well…actually: Are you really sure you want to parse HTML using rational expressions, is that not so rational in itself?