php - preg_match acting very strange -
i using preg_match()
extract pieces of text variable, , let's variable looks this:
[htmlcode]this supposed displayed[/htmlcode] middle text [htmlcode]this supposed displayed[/htmlcode]
i want extract contents of [htmlcode]
's , input them array. doing using preg_match()
.
preg_match('/\[htmlcode\]([^\"]*)\[\/htmlcode\]/ms', $text, $matches); foreach($matches $value){ return $value . "<br />"; }
the above code outputs
[htmlcode]this supposed displayed[/htmlcode]middle text[htmlcode]this supposed displayed[/htmlcode]
instead of
- [htmlcode]this supposed displayed[/htmlcode]
- [htmlcode]this supposed displayed[/htmlcode]
and if have offically run out of ideas
as explained already; *
pattern greedy. thing use preg_match_all()
function. it'll return multi-dimension array of matched content.
preg_match_all('#\[htmlcode\]([^\"]*?)\[/htmlcode\]#ms', $text, $matches); foreach( $matches[1] $value ) {
and you'll this: http://codepad.viper-7.com/z2gusd
Comments
Post a Comment