<?php
preg_match_all('/<!-- BEGIN test -->(.*?)<!-- END test -->/','<?php echo $this->_VARS['TEST']; ?> <br />
<?php $this->_include('plik_testowy.tpl'); ?>
<!-- BEGIN test -->
{test.AAA}
<!-- END test -->',$matches2);
?>
Wyświetla "!ok". Print_r($matches2) daje tablicę złożoną z 2 pustych tablic. Co jest źle?
I $pattern, $this->content są takie same jak w preg_match_all.
Cały plik (błąd występuje w template_compile::parse_loops):
<?php
header('content-type: text/plain'); class template_compile
{
public function __construct($dir)
{
$this->dir = $dir;
return true;
}
public function compile()
{
$files = glob($this->dir . 'tpl_*.tpl'); foreach ($files as $file_id => $file_name)
{
$this->compile_exec($file_name);
}
return true;
}
public function compile_file($file_name)
{
$this->compile_exec($tis->dir . 'tpl_' . $file . '.tpl');
return true;
}
private function compile_exec($file)
{
{
}
$this->parse_vars();
$this->parse_includes();
$this->parse_ifs();
$this->parse_loops();
return true;
}
private function parse_vars()
{
foreach ($matches[0] as $id => $search)
{
{
$this->content = str_replace($search,'<?php echo $this->_VARS['' . $matches[1
][$id] . '']; ?>',$this->content); }
}
return true;
}
private function parse_includes()
{
foreach ($matches[1] as $id => $file)
{
$this->content = str_replace($matches[0
][$id],'<?php $this->_include('' . $file . ''); ?>',$this->content); }
return true;
}
private function parse_ifs()
{
foreach ($matches[1] as $id => $if)
{
//
}
return true;
}
private function parse_loops()
{
foreach ($matches[1] as $id => $loop_name)
{
$pattern = '/<!-- BEGIN ' . $loop_name . ' -->(.*?)<!-- END ' . $loop_name . ' -->/';echo
$pattern; echo $this->content; foreach ($matches2[1] as $id2 => $code)
{
$new_code = $code;
foreach ($matches2[1] as $id123 => $search)
{
{
$new_code = str_replace($search,'<?php echo $this->_BLOCK_VARS[' . $loop_name . '][' . $matches2[1
][$id123] . ']; ?>',$new_code); }
}
$this->content = preg_replace('/<!-- BEGIN ' . $loop_name . ' -->' . $new_code . '<!-- END ' . $loop_name . ' -->/','<?php foreach ($this->_BLOCK_VARS['' . $loop_name . ''] as $id => $value){eval('<?php' . ' . $new_code . ' . '?>');} ?>',$this->content); }
}
return true;
}
}
?>
<?php
$tc = new template_compile('tpl/');
$tc->_VARS['test'] = 'zmienne: działają';
$tc->_BLOCK_VARS
['test'] = array( 'test.AAA' => 'loopy ok'
);
$tc->compile();
?>
tpl/test.tpl:
Kod
{TEST}
<!-- INCLUDE plik_testowy.tpl -->
<!-- BEGIN test -->
fghj{test.AAA}aa
<!-- END test -->