Hey 
i have programmed a template system for a project i am working on. i am having problems when the template has nested ifs inside it. i can't think of a way to parse those ifs correctly.
here is an example (my template system tags are enclosed in %%):
%if_login%
user logged in
%if_user_admin%
you are an admin! welcome....
%end_if%
here is some more text in case the user has logged in.....
%else%
%if_logoff%
you logged off succesfully!
%end_if%
you need to login...
print login form here....
%end_if%
now the problem is i was trying to use the following regular expression to process the if statements:
$my_pattern = preg_replace("/%if_([^%]+)%(.*?)(?:%else%(.*?)|)%end_if%/ise", "\$this->process_if('\\1', '\\2', '\\3', \$iterate)", $my_pattern);
it works well if there are no nested ifs, but when it encounters a nested if, it takes the wrong %end_if% and all gets mixed up...i wanted to have a function that will not mind the number of if statements...
i tried using preg_split to split as follwos: preg_split('/(%(?:if_[^%]+|else)%)(.*?)/is',$data, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
and then looping on that but i am totally stuck! my head went blank...
any ideas on how to crack this one?!
cheers!
(-:
i have programmed a template system for a project i am working on. i am having problems when the template has nested ifs inside it. i can't think of a way to parse those ifs correctly.
here is an example (my template system tags are enclosed in %%):
%if_login%
user logged in
%if_user_admin%
you are an admin! welcome....
%end_if%
here is some more text in case the user has logged in.....
%else%
%if_logoff%
you logged off succesfully!
%end_if%
you need to login...
print login form here....
%end_if%
now the problem is i was trying to use the following regular expression to process the if statements:
$my_pattern = preg_replace("/%if_([^%]+)%(.*?)(?:%else%(.*?)|)%end_if%/ise", "\$this->process_if('\\1', '\\2', '\\3', \$iterate)", $my_pattern);
it works well if there are no nested ifs, but when it encounters a nested if, it takes the wrong %end_if% and all gets mixed up...i wanted to have a function that will not mind the number of if statements...
i tried using preg_split to split as follwos: preg_split('/(%(?:if_[^%]+|else)%)(.*?)/is',$data, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
and then looping on that but i am totally stuck! my head went blank...
any ideas on how to crack this one?!
cheers!
(-: