For a small sized template engine, I’m trying to use a preg_replace to replace
{INCLUDE:dir/file.inc.php}
with the proper PHP equivalent.
I’ve tried using the following, but the / in the include path results in a “Division by zero” error:
$template = preg_replace('~\{INCLUDE:(.*?)}~', '<?php echo $1; ?>', $template);
(the echo in the preg_replace is for debugging purposes, will be an include eventually)
When I remove the / from the include path (so it’s just file.inc.php), it still removes all dots.
Any help would be greatly appreciated!
If I understood you correctly I think this should work just fine
Your problem was caused by unquoted $1.