Joran Den Houting
Joran Den Houting

Reputation: 3163

Preg match all won't find the string

My preg_match_all function:

preg_match_all("{lang:(.*?)}", $template, $found_langs);

The template is like:

<h1>{lang:Choose sport}</h1>

But it won't find it... BUT if I use this:

preg_match_all("{lang:(\w*)}", $template, $found_langs);

It'll find Choose. I need to find Choose sport..

Anyone knows why (.*?) won't work?

Upvotes: 1

Views: 99

Answers (1)

Victor Bocharsky
Victor Bocharsky

Reputation: 12306

Try to escape { char and use // for RegEx pattern in preg_match_all:

preg_match_all("/\{lang:(.*?)\}/i", $template, $found_langs);

And //i at the end of pattern is a case insensitivity.

Upvotes: 7

Related Questions