使用tpl文件在php中进行模板化

使用tpl文件在php中进行模板化,php,templating,Php,Templating,虽然页脚和页眉文件不是空的,但这段代码没有生成任何输出,这是正确的吗 $this->includes=preg\u match\u all('/{include\“[^}]\“*}/',$data,$this->includes) 执行后,$this->includes将包含单个整数或布尔值false 看我敢说是因为这条线 $this->includes=preg\u match\u all('/{include\“[^}]\“*}/',$data,$this->includes) 执行后,$t

虽然页脚和页眉文件不是空的,但这段代码没有生成任何输出,这是正确的吗

$this->includes=preg\u match\u all('/{include\“[^}]\“*}/',$data,$this->includes)

执行后,
$this->includes
将包含单个整数或布尔值
false


我敢说是因为这条线

$this->includes=preg\u match\u all('/{include\“[^}]\“*}/',$data,$this->includes)

执行后,
$this->includes
将包含单个整数或布尔值
false


请参见

我想知道这一行是否符合您的意图:

$data = {include "header.tpl"}{include "footer.tpl"};

private function get_tpl_includes($data){
        $this->includes = preg_match_all('/{include \"[^}]\"*}/', $data, $this->includes);

        foreach($this->includes as $include){
            $tpl_file = $this->dir . str_replace($this->dir, "", $include[0]);
            $html_include = file_get_contents($tpl_file) or die("tp3"); //Get the content of the included html
            $pattern = '{include "' . $tpl_file . '"}'; //Create a pattern to replace in the html
            $this->html = str_ireplace($pattern, "", $this->html); //Replace the file include pattern with html
        }

    }
preg\u match\u all
返回匹配数。您将其作为第三个参数传递并分配

此外,我想你错过了这里的引语:

$this->includes = preg_match_all('/{include \"[^}]\"*}/', $data, $this->includes);

我想知道这条线是否符合您的意图:

$data = {include "header.tpl"}{include "footer.tpl"};

private function get_tpl_includes($data){
        $this->includes = preg_match_all('/{include \"[^}]\"*}/', $data, $this->includes);

        foreach($this->includes as $include){
            $tpl_file = $this->dir . str_replace($this->dir, "", $include[0]);
            $html_include = file_get_contents($tpl_file) or die("tp3"); //Get the content of the included html
            $pattern = '{include "' . $tpl_file . '"}'; //Create a pattern to replace in the html
            $this->html = str_ireplace($pattern, "", $this->html); //Replace the file include pattern with html
        }

    }
preg\u match\u all
返回匹配数。您将其作为第三个参数传递并分配

此外,我想你错过了这里的引语:

$this->includes = preg_match_all('/{include \"[^}]\"*}/', $data, $this->includes);