php - 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}}"/>
解决方案
推荐阅读
- sql - 在 SQL 中将多行转换为新列
- java - 带有参数无法识别方法的 Mockito ArgumentMatcher lambda 函数
- javascript - 使用类型模块访问脚本标记中定义的变量?
- wso2 - 如何使用 Keytool 从 .jks 文件中导出公钥?
- node.js - NodeJs + React multer设置错误
- c++ - Sysmalloc:使用向量的断言错误
- bash - 如何将任意参数传递给通过 SSH 执行的命令?
- ios - 我只能加载一次视图控制器吗?
- selenium-webdriver - VSTS 构建错误 - 配置和平台
- node.js - npm copyfiles 维护完整路径