|
|
|
| Использую шаблонизатор такого типа
<?php
Class parsing_php
{
function Parse_tpl ()
{
$template="Template/Template0001.tpl";
$file=file_get_contents($template);
$tpls['title']="значение1";
$tpls['style']="значение2";
$tpls['content']="значение3";
$tpls['main']="echo \"hello\";";
foreach($tpls as $key=>$val)
{
$file=str_replace("*".strtoupper($key)."*",$val,$file);
}
echo $file;
}
}
$Class=new Renewing_php;
$Class->Parse_tpl();
?>
|
всё прекрасно работает...но вместо того чтобы в шаблоне через строчку
$tpls['main']="echo \"hello\";"; выводить "hello" он выводит прямо echo "hello"; как зделать так чтоб код внутри шаблона выполнялся? | |
|
|
|
|
|
|
|
для: Alph[p]a
(13.11.2006 в 23:44)
| | Сохраняешь $file в какой-то файл и инклудишь его... Вроде должно работать | |
|
|
|
|
|
|
|
для: fraer
(14.11.2006 в 00:35)
| | А можно на примере..а то целый день с этой фигнёй возился..мозги не работают.. | |
|
|
|
|
|
|
|
для: Alph[p]a
(14.11.2006 в 00:41)
| |
<?php
Class parsing_php
{
function Parse_tpl ()
{
$template="Template/Template0001.tpl";
$file=file_get_contents($template);
$tpls['title']="значение1";
$tpls['style']="значение2";
$tpls['content']="значение3";
$tpls['main']="echo \"hello\";";
foreach($tpls as $key=>$val)
{
$file=str_replace("*".strtoupper($key)."*",$val,$file);
}
$fff = "tmp001.php";
file_put_contents($fff, $file);
return $fff;
}
}
$Class=new Renewing_php;
$inc_f_name = $Class->Parse_tpl();
include($inc_f_name);
?>
|
Не забудь натыкать <?php и ?> где надо в шаблоне!!! | |
|
|
|
|
|
|
|
для: fraer
(14.11.2006 в 00:49)
| | Я тут начитал что ф-ия file_put_contents работает токо на php5, заменил на
<?php
Class parsing_php
{
function Parse_tpl ()
{
$template="Template/Template0001.tpl";
$file=file_get_contents($template);
$tpls['title']="значение1";
$tpls['style']="значение2";
$tpls['content']="значение3";
$tpls['main']="echo \"hello\";";
foreach($tpls as $key=>$val)
{
$file=str_replace("*".strtoupper($key)."*",$val,$file);
}
$fff = "tmp001.php";
$handle = fopen($fff, "w+");
fwrite($handle, $file);
fclose($handle);
return $fff;
}
}
$Class=new Renewing_php;
$Class->Parse_tpl();
include($fff);
?>
|
выводит Warning: main() [function.main]: Failed opening '' for inclusion (include_path='.;c:\php4\pear') in E:\Apache\Apache2\htdocs\1\index.php on line 28 это типа так файл не видит..?
заменил
<?php
Class parsing_php
{
function Parse_tpl ()
{
$template="Template/Template0001.tpl";
$file=file_get_contents($template);
$tpls['title']="значение1";
$tpls['style']="значение2";
$tpls['content']="значение3";
$tpls['main']="echo \"hello\";";
foreach($tpls as $key=>$val)
{
$file=str_replace("*".strtoupper($key)."*",$val,$file);
}
$fff = "tmp001.php";
$handle = fopen($fff, "w+");
fwrite($handle, $file);
fclose($handle);
return $fff;
}
}
$Class=new Renewing_php;
$Class->Parse_tpl();
include(tmp001.php);
?>
|
тогда получаю : Warning: main(tmp001php) [function.main]: failed to create stream: No such file or directory in E:\Apache\Apache2\htdocs\1\index.php on line 28
Warning: main() [function.main]: Failed opening 'tmp001php' for inclusion (include_path='.;c:\php4\pear') in E:\Apache\Apache2\htdocs\1\index.php on line 28
Вообще странно..(файл tmp001.php создаётся и инфа туда пишеться) Что делать? | |
|
|
|
|
|
|
|
для: Alph[p]a
(14.11.2006 в 01:32)
| |
Должен быть более красивый метод. Если до утра придумаю - напишу! | |
|
|
|
|
|
|
|
для: fraer
(14.11.2006 в 01:37)
| |
<?php
Class parsing_php
{
function Parse_tpl ()
{
$template="Template/Template0001.tpl";
$file=file_get_contents($template);
$tpls['title']="значение1";
$tpls['style']="значение2";
$tpls['content']="значение3";
$tpls['main']="echo \"hello\";";
foreach($tpls as $key=>$val)
{
$file=str_replace("*".strtoupper($key)."*",$val,$file);
}
$fff = tempnam("/tmp", "tmpl");
$handle = fopen($fff, "w");
fwrite($handle, $file);
fclose($handle);
return $fff;
}
}
$Class=new Renewing_php;
$tmp_name = $Class->Parse_tpl();
include($tmp_name);
unset($tmp_name);
?>
|
Пробуй... | |
|
|
|
|
|
|
|
для: fraer
(14.11.2006 в 01:53)
| | Тоже работает.. А можно по подробнее про $fff = tempnam("/tmp", "tmpl"); ?? tempnam чё она делает??? | |
|
|
|
|
|
|
|
для: fraer
(14.11.2006 в 01:37)
| | Огромное спасибо.Если че надумаешь, то я обязательно почитаю... | |
|
|
|
|
|
|
|
для: Alph[p]a
(13.11.2006 в 23:44)
| | Можно обойтись без создания файла. Функция eval() исполняет переданную ей строку как PHP-код | |
|
|
|