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 ='/([\s\S]*)<\/div>/ ';
It’s a bit tricky.
The problem is if I have two divs-like this.
text to extract here
text to extract from here as well
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
text to extract from here as well
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?
I am trying to use regexp to find eveything in a div. I know there may be a smarter way – but I chose regexp.
< p>So currently my regular expression pattern is as follows:
$gallery_pattern ='/([\s\S]*)<\ /div>/';
It does the trick.
The problem is if I have two divs-like this.
text to extract here
text to extract from here as well
I want to extract from here The information is extracted from a div, but my problem during the test is that I did not get the result between the text, but:
"text to extract here
< br />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.
In the div The text can contain <,/ and newline characters. Just you know! Does anyone have a simple solution to this problem? I am still a novice at regular expressions.
How about something like this:
$ str = <<text to extract here
text to extract from here as well
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?