首页 > 解决方案 > PHP 模板不起作用,我制作了一个 php 模板引擎,但无法将输出与 implode 合并

问题描述

我为我的框架编写了一个模板。我不知道如何将这两个文件合并到输出中。我尝试使用 implode 来合并 foreach 输出;我期待一个字符串,但我得到了一个 int。

我的代码:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class render {
    function set($title, $inputParam) {
        $wrapper = file_get_contents("temp/top.php");
        $input = file_get_contents("temp/bottom.php");
        $wrapper = str_replace("{{title}}", $title, $wrapper);
        $inputArr = array();
        foreach($inputParam as $inputHTML) {
            $inputCode = str_replace("{{value}}", $inputHTML, $input);
            echo $inputCode;
        }
    } 
}
?>
top
<?php
$div = new render();
echo $div->set("a title", array("input number 1", "hello world"));
?>
bottom
<?php
$div = new render();
echo $div->set("a title", array("input number 1", "hello world"));
?>

top.php 是这样的:

<h1>{{title}}<div>{{content}}</div></h1>

底部.php

<input name="" value="{{value}}"/>

标签: php

解决方案


推荐阅读