1
$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
        }

    }

这段代码是否正确,因为尽管页脚和头文件不为空,但它没有产生任何输出。

4

2 回答 2

1

我敢说是因为这条线

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

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

http://php.net/manual/en/function.preg-match-all.php

于 2011-02-16T00:15:04.840 回答
0

我想知道这条线是否符合您的预期:

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

preg_match_all返回匹配的数量。您将它作为第三个参数传递并分配它。

此外,我想你在这里错过了报价:

$data = '{include "header.tpl"}{include "footer.tpl"}';
于 2011-02-16T00:19:17.253 回答