I am attempting to use preg_match_all to extract a repeated pattern out of an html string.
The problem seems to be that my pattern has a defined beginning and end, but a wildcard portion in between. So the preg_match_all ends up only getting the biggest match, but not the individual matches.
My ultimate goal is to isolate each <a ...>some text</a> out of an html string, and to wrap them as so: <font ...><a ...>some text</a></font>.
But first off I want to simply successfully isolate them each:
$lvs_regex = "/<a.+<\/a>/" ;
$lvs_test = "click <a href='...'>AAA</a> now, <a href='...'>BBB</a> later, <a href='...'>CCC</a> tomorrow" ;
preg_match_all( $lvs_regex , $lvs_test , $matches ) ;
for($i = 0 ; $i < count( $matches ) ; $i++ )
{ print $matches[ $i ][0] . "<br/>" ;
}
The return that I want:
[0] => <a href='...'>AAA</a>
[1] => <a href='...'>BBB</a>
[2] => <a href='...'>CCC</a>
But I only get one match:
[0] => <a href='...'>AAA</a> now, <a href='...'>BBB</a> later, <a href='...'>CCC</a>
.*?or use a negated character class to only match non-tagish content in between.<font>tags, why you don't use a css rule?