Hi,
Does anyone know of a way of passing other variables to the function being called by this preg_replace_callback? For instance, I have the following code:
function smarty_compile_lang($tpl_source) {
// en.php contains a very large array, $lang
include_once '/home/test/en.php';
return preg_replace_callback('/##(.+?)##/', 'compile_lang', $tpl_source);
}
/**
compile_lang
*/
function compile_lang($key){
// If I include $lang here then it gets
// loaded again and again - bad for performance
return $lang[$key[1]];
} // End _compile_lang
Somehow I need to make $_lang global, or pass it through the function preg_replace_callback - which I don't think is possible?
What can I do? I've tried a global statement everywhere I can think of... and I don't want to include en.php outside the functions, as it'll be included then whether the templates are being compiled or not.
TIA,
Peter.