<?php $str='{{ b.id + $c.id }} '; $result = preg_replace_callback('/{{\s*\$?\w+\.\w+(?:\s*\+\s*\$?\w+\.\w+\s*)*}}/m', function ($match) { return preg_replace('/(\$?\w+)\.(\w+)/m','$1[\'$2\']',$match[0]); }, $str); printf($result); ?>
preg_replace_callback $string = preg_replace_callback('/\b$([\w_+])\b/', function ($match, $key) { }, $string);