Greetings,
I come from a perl background, and I'm still learning quite a few differences between perl and PHP. I've stumbled across a problem in a template engine that I'm working on. The engine works by reading the template into $buffer, making the required replacements, and then spitting it back out. Within the template, there are REM tags such as "<!-- insert(title) do(long) -->", for example.
Now the part within the parens just after the "insert", in this case "title", is a function. Each function is set to return a certain type of data which will replace the REM tag. I want to limit the functions that a person can call this way (to avoid corruption). Say I want to limit the function calls to "title", "news" and "url", how would I do this with the replacement code that I have so far?
Here is a code snippet thus far (assume $buffer is the template text):
$buffer = preg_replace('/<!--\sinsert((.+?))\s(\S)\s-->/e', '\1(\2)', $buffer);
Obviously, i'm calling a function defined by the first value (\1) with a variable of the second value (\2). The first value is the one that actually calls the function, so that's the one I'd like to compare.
As a side note, the previous prototype of this code used the preg_match function with the function_exists function. Alas, the problem here was that the code wasn't replacing all the tags with the proper values, AND it would allow users to call any function -- thus allowing people to really screw up their output code.
Any help would greatly be appreciated.