Emanuel Schiendorfer Emanuel Schiendorfer - 4 months ago 97
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

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)