I have the following line of code:
$message = preg_replace('/\{\{([a-zA-Z_-]+)\}\}/e', "$$1", $body);
This replaces words surrounded by two curly brackets with variables of the same name. ie {{username}} gets replaced by $username.
I am trying to convert it to use preg_replace_callback. This is my code so far based on Googling, but I'm not really sure what I am doing! The error_log output is showing the variable name including the curly brackets.
$message = preg_replace_callback(
    "/\{\{([a-zA-Z_-]+)\}\}/",
        function($match){
            error_log($match[0]);
            return $$match[0];
        },
        $body
);
Any help greatly appreciated.
 
     
    