Alright, I'm struggling to get a template class (smarty like) going on right here, and I've made it, up to some point. Simple vars, like $a, $some_var, $a_v4r and such are correctly parsed by this simple rule: (variables will look like {$this_is_a_var} in the HTML code)
Code:
$this->output = preg_replace( "/\{\$([a-zA-Z0-9_\-]+?)\}/", '$this->vars[\'\\1\']', $this->output );
But, I cannot replace arrays, for some reason. If I try the php syntax, like {$array['index1']['index2']}, the script is complaining about unescaped quotes and stuff like that. I've managed to get a way working (the smarty way - $arr.index1.index2), but still won't work right. So far I've managed to do this (but notice, however, that only the last part of the array is captured - e.g.: $array['a'][0] would output $array[0], no matter how many keys I add there):
Code:
$this->output = preg_replace( "/\{\$([a-zA-Z0-9_\-]+?)(\['?(?:[a-zA-Z0-9]+?)'?\])*\}/e", '$this->vars[\'\\1\']\\2', $this->output );
I store these template vars into an array, component of a class, like so:
Code:
$this->template_vars = array( 'test_var' => 'some sample var',
'array' => array( 'a' => 'test', 1, 2, 3 ) );
Please help me out with some tips, or a direction, anything. Thanks in advance.
Also, if someone has a little free time & knowledge, please try to respond to the last question of this topic:
RegEx It would help me alot. Thanks.