Hello, I have to parse this template file ($html) :
{$myFirstVariable}
{$myMainVar:MYF1,"x\:x\,x",2:MYF2:MYF3,false}
{$myLastVariable:trim}
Following, my php parser :
$regexp = '#{\$(?<name>.+?)(\:(?<modifiers>.+?))?}#';
preg_replace_callback($regexp, 'separateVariable', $html);
function separateVariable($matches) {
$varname = $matches['name'];
print $varname."\n";
if (isset($matches['modifiers'])) {
$modifiers = $matches['modifiers'];
$modifiers = preg_split('#(?<!\\\):#', $modifiers);
$parsed = array();
foreach ($modifiers as $modifier) {
$modifier = preg_split('#(?<!\\\),#', $modifier);
$parsed[array_shift($modifier)] = $modifier;
}
// parsed[myFuncName] = Array(2ndArg, 3rdArg)
print_r($parsed);
}
print "\n";
}
All working except i've to escape ':' and ',' in {$myMainVar:...} with an '\'.
Do you have any solution to free me up of '\' ?
Thanks.