开发者

i preg_replace and get only last char of the statement. help

开发者 https://www.devze.com 2023-01-27 00:46 出处:网络
I\'ve got a terrible problem. There are a lot of constructions like {{SOME_WORDS}} in my string and I want to change it for $lang[\'some_word\']. For this reason I use something like:

I've got a terrible problem. There are a lot of constructions like {{SOME_WORDS}} in my string and I want to change it for $lang['some_word']. For this reason I use something like:

$cache=preg_replace('/({{)+([A-Z_])+(}})/u','$2',$cache);

and got only last char of SOME_WORDS "S". The next problem is to put 开发者_StackOverflow社区$lang[strtolower($2)] into preg_replace second argument. Or there could be another solution?


you need to put the + inside the parentheses. like this:

$cache=preg_replace('/({{)+([A-Z_]+)(}})/u','$2',$cache);


try this:

$cache = preg_replace("/\{\{(\w+)\}\}/e", "strtolower($1)", $cache);
0

精彩评论

暂无评论...
验证码 换一张
取 消