Emanuel Schiendorfer Emanuel Schiendorfer - 1 year ago 335
Smarty Question

Counting preg_match in smarty

How to count preg_match matches in smarty? Why is the following not working?

{preg_match("/\[PGN.*](.*)\[\/PGN.*\]/", $code, $match)}

{$match|@count}

Answer Source

As far as I understand your needs, the following does work, just make the regex not greedy:

preg_match_all("~\[PGN\d+](.+?)\[/PGN\d+]~", $code, $match)