13-04.php
来自「《php程序设计》的配套源码 《php程序设计》的配套源码 《php程序」· PHP 代码 · 共 27 行
PHP
27 行
function FillTemplate($inName, $inValues = array(),
$inUnhandled = "delete") {
$theTemplateFile = $_SERVER['DOCUMENT_ROOT'] . '/templates/' . $inName;
if ($theFile = fopen($theTemplateFile, 'r')) {
$theTemplate = fread($theFile, filesize($theTemplateFile));
fclose($theFile);
}
$theKeys = array_keys($inValues);
foreach ($theKeys as $theKey) {
// look for and replace the key everywhere it occurs in the template
$theTemplate = str_replace("\{$theKey}", $inValues[$theKey],
$theTemplate);
}
if ('delete' == $inUnhandled ) {
// remove remaining keys
$theTemplate = eregi_replace('{[^ }]*}', '', $theTemplate);
} elseif ('comment' == $inUnhandled ) {
// comment remaining keys
$theTemplate = eregi_replace('{([^ }]*)}', '<!-- \\1 undefined -->',
$theTemplate);
}
return $theTemplate;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?