Answer the question
In order to leave comments, you need to log in
Template engine with functions
I am writing my own stencilizer, but I ran into the problem of calling functions in templates
. I will give an example:
...
'@\[\+rand\(([0-9]+)-([0-9]+)\)\+\]@si' => rand(intval("$1"), intval("$2")),
...
Answer the question
In order to leave comments, you need to log in
Everything is working:
echo preg_replace_callback(
'@\[\+rand\(([0-9]+)-([0-9]+)\)\+\]@si' ,
function($m){return rand(intval($m[1]), intval($m[2]));},
'test [+rand(4-10)+] test');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question