php Ä£°åд·¨
<?php
/* @author: zhuyubing@gmail.com */
class Template{
var $code;
function Template($template){
$this->code = implode('', @file($template));
}
function assign($name,$var=null){
if(is_string($name) && is_string($var)){
$this->code = str_replace('{'.$name.'}', $var, $this->code);
} else if(is_array($var)){
list($this->code,$tmp,$end)=explode('<!--'.$name.'-->',$this->code);
while(list(,$v)=each($var)){
$t=$tmp;$k2=$v2='';
while(list($k2, $v2) = each($v)){
$t = str_replace('{'.$k2.'}', $v2,$t);
}
$this->code .= $t;
}
$this->code .= $end;
} else {
while (list ($k2, $v2) = each($name)){
$this->code = str_replace('{'.$k2.'}', $v2, $this->code);
}
}
}
function display(){
echo $this->code;
}
}
?>
×î¼òµ¥µÄhello_world
×¼±¸Ò»¸öphpÄ£°æÎļþhello_world.html
<html>
<head>
<meta http-equiv="Content-Type" c />
<title>{title}</title>
</head>
<body>
<h1>{title
Ïà¹ØÎĵµ£º
¡¶Head First
Éè¼ÆÄ£Ê½¡·ÊDZ¾²»´íµÄ½²½âÉè¼ÆÄ£Ê½µÄÊ飬²»ÏñF4дµÄÄÇô¿ÝÔӦ¸ÃËãÊDZȽÏÈÝÒ×Àí½âµÄºÃÊé¡£ÊéÖеÄÀý×Ó¶¼±È½ÏdzÏÔÒ×¶®£¬²»¹ýÓÉÓÚÊÇÍâ¹úÀÐдµÄ£¬ËùÒÔÀý×Ó
µÄϰ¹ß²»ÊǺܸ½ºÏÖйúÌØÉ«£¬¿ÉÄÜż¶û¿´ÆðÀ´ÓÐЩ±ðŤ£¬»¹ÓÐÓïÑÔϰ¹ßÒ²²»ÊÇÖйú·ç¡£µ±È»¿´¹ýÕâ±¾ÊéÖ®ºó£¬Äã²ÅÄÜÉî¿ÌÀí½âÉè¼ÆÄ£Ê½µ½µ×ÄÜΪÄã½â¾öÄÄЩ
퉣 ......
/***************************by garcon1986**************************/
form.html
<html>
<head>
<title>Upload File</title>
</head>
<body>
<form enctype="multipart/form-data" method="POST" action="uploader.php">
<label> ......
php¹Ø¼ü´Ê
phpÖÐÓÃÓÚÎļþ°üº¬µÄ¹Ø¼ü´ÊÓÐ:include¡¢include_once¡¢require¡¢require_once¡£Ò»°ãÀ´Ëµ£¬°ÑincludeºÍrequire·ÖÔÚÒ»×éÀ¶øinclude_onceºÍrequire_onceÊÇÒ»ÖָĽøÍêÉÆÐÎʽ¡£±¾ÎÄͨ¹ýÑо¿includeºÍrequireµÄÐÔÖÊ£¬¼æ¹Ëinclude_onceºÍrequire_once£¬»ñµÃphpÎļþ°üº¬µÄ»ù±¾ÖªÊ¶ºÍDZÔÚ ......