У меня есть следующий сценарий.
Каждый раз, когда загружается моя страница, я создаю файл. Теперь у моего файла есть два тега. {theme} {/ theme} и {layout} {/ layout}, теперь каждый раз, когда я выбираю определенный макет или тему, он должен заменять теги на {layout} layout {/ layout} и {theme} theme {/ theme}
Моя проблема в том, что после запуска следующего кода
if(!file_exists($_SESSION['file'])){
$fh = fopen($_SESSION['file'],"w");
fwrite($fh,"{theme}{/theme}\n");
fwrite($fh,"{layout}{/layout}");
fclose($fh);
}
$handle = fopen($_SESSION['file'],'r+');
if ($_REQUEST[theme]) {
$theme = ($_REQUEST[theme]);
//Replacing the theme bracket in the cache file for rememberence
while($line=fgets($handle)){
$line = preg_replace("/{theme}.*{\/theme}/","{theme}".$theme."{/theme}",$line);
fwrite($handle, $line);
}
}
Мой вывод выглядит следующим образом
{theme}{/theme}
{theme}green{/theme}
И это должно выглядеть так
{theme}green{/theme}
{layout}layout1{/layout}