一 代码
config文件
title = "调用配置文件" bgcolor = "#f0f0f0" border = "5" type = "计算机类" name = "PHP从入门到精通"
tpl模板文件
{config_load file="4.conf"}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>{#title#}</title>
<link rel="stylesheet" href="../css/style.css" />
</head>
<body bgcolor="{#bgcolor#}">
<table border="{#border#}">
<tr>
<td>{$smarty.config.type}</td>
<td>{$smarty.config.name}</td>
</tr>
</table>
</body>
</html>
php文件
<?php
include_once '../config.php';
$smarty->display('4/index.tpl');
?>
二 运行结果
本文介绍了一个使用Smarty模板引擎结合PHP配置文件的具体案例。案例中详细展示了如何通过PHP加载配置文件,并将配置信息展示在网页上。具体包括配置文件的定义、模板文件的设置及最终的PHP代码实现。
1988

被折叠的 条评论
为什么被折叠?



