Hi, What I need is to match all the texts between <!-- message --> and <!-- / message --> I have tried using this: function findinside($start, $end, $string) { preg_match_all('/' . preg_quote($start, '/') . '([^\.)]+)'. preg_quote($end, '/').'/i', $string, $m); return $m[1]; } $start="<!-- message -->"; $end="<!-- / message -->"; $data="<!-- message -->text1<!-- / message --><!-- message -->text2<!-- / message --><!-- message -->text3<!-- / message -->"; $out = findinside($start, $end, $data); print_r ($out); PHP: but it will only show the first result Later edit: seems like the problem is the / from $end but i still haven't came out with a fix
function findinside($tag, $string) { $pattern = '/<!-- '.preg_quote($tag).' -->(.*?)<!-- \/ '.preg_quote($tag).' -->/si'; preg_match_all($pattern, $string, $m); return $m[1]; } $tag = 'message'; $data="<!-- message -->text1<!-- / message --><!-- message -->text2<!-- / message --><!-- message -->text3<!-- / message -->"; $out = findinside($tag, $data); print_r ($out); PHP:
It means that a . will match all characters, but also will match new lines. Without it, it will not match a new line character as well See here for more info on regex patter modifiers