The essence of this. I have a tpl file containing the text. I include this file in php-code through the function file();
Everything is working. I start the line output of this file - it also works. Now I need a small parser, which, when it detects a special construct, will replace it with another text. Here is the text of the tpl file
[php]peremena[/php]
Actually php-code itself:
$peremena = 33; //переменная для замены $php_codes = array( //собственно сами условия замены "\[php\](.+)\[/php\]" => "$1" ); $tpl_file = file('page.general.tpl'); //подгрузка файла foreach ($tpl_file as $line_num => $line){ //построчный вывод файла foreach ($php_codes as $key => $php_code) //сам парсер $line = preg_replace("#".$key."#isU", $$php_code, $line); //замена текста на переменную, имя которой содержится в $php_code echo $line; //вывод строки }
In this example, I want to replace the text [php]peremena[/php]
with the value of the $peremena
variable - 33. I realized that the $php_code
variable contains the text "$1"
, which is the function preg_replace();
replaces the key with the text peremena
. But I need that this text was displayed programmatically, like a variable, in order to substitute the values of a variable with this name there. How to do it?