Forum Moderators: coopster
[webmasterworld.com...]
But I want to use it with POST vars from a form submission. It doesn't seem to be working. The original from Vince is:-
print preg_replace("/\{([^\{]{1,100}?)\}/e","$values[$1]",file_get_contents("template.tpl"));
... and I'd like to use this:-
print preg_replace("/\{([^\{]{1,100}?)\}/e","$_POST[$1]",file_get_contents("template.tpl"));
... but it generates this error:-
syntax error, unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE or T_NUM_STRING
I'm not quite sure how to reference to global $_POST var or if what I want to do is even possible.
Any ideas gratefully received!
Try it without the quotes. Other than that everything looks fine so make sure the syntax error isn't coming from someplace else.
print preg_replace("/\{([^\{]{1,100}?)\}/e", "\$_POST['$1']", file_get_contents("template.tpl"));
It seems it was looking for a grouped section in the pattern to replace $_... but that's not correct syntax. I escaped the dollar sign and it seems to work correctly. I'm not sure, however, why the original code worked and not your modified version.
Many thanks for your help.
I'm not sure, however, why the original code worked and not your modified version.
Me either. I'm not 100% sure that it did - could have been some caching that made me think it was working, due to the design of this app.
I'll investigate further...