I have the following pattern using it to match HTML tags:
~<([[:alpha:]]+) ([[:alpha:]]+=".*?")*>.*?</\1>~si
It works fine and will match any tag, but it will only search throughout the string for the first match it encounters. For example:
$text = <<<text
<p class="matches">some text, this will match</p>
<p>this won't match</p>
<p>this won't match either</p>
<p class="matches">this will match</p>
<p class="matches">this will match too</p>
<div>This won't match either but I want it to..</div>
text;
$pattern = '~<([[:alpha:]]+) ([[:alpha:]]+=".*?")*>.*?</\1>~si';
preg_match_all($pattern,$text,$matches);
var_dump($matches);
The code posted will fill $matches as I want it to, but $matches[0][*] will only contain the 3 paragraphs that have the class="matches" attribute (I tested this pattern on tags without attributes and it does match those properly too). Rexexp is not my forté... What am I doing wrong?
but that really doesn't matter in this case. – Yoshi Apr 27 '11 at 03:39
first part of the text> second part`?
– eyelidlessness May 21 '12 at 21:22