test.html
<title>{title}</title>test.php
$title='surfchen\'s home';
$tpl=implode('{title}',$title,$tpl);
echo $tpl;

解决方案 »

  1.   

    不能用啊。
    那个$tpl是什么东西啊?
      

  2.   

    sorry,it's my fault....test.php
    $title='surfchen\'s home';
    $tpl=implode('',file('test.html'));
    $tpl=str_replace('{title}',$title,$tpl);
    echo $tpl;
      

  3.   

    用别人的东西吧,
    FastTemplate ,phplib
    可以满足到你的要求。
    用心一点学一下就可以学会的。
      

  4.   

    PHPLIB  SMARTY  哇咔咔
    去找找教程
      

  5.   

    PHPLIB不庞大。整个模板类仅一个文件。 include 过去即可。~~~~~~~
      

  6.   

    要看你自己了,如果你有其他相关经验,很容易想到解决方案,PHP也是很类似的.
    还可以充分利用js来分离代码。(输出模板和js,在客户端生成最终效果。)
      

  7.   

    有编程经验。如ms sql server, c#, delphi等。
    只是现在公司要求做网页,要有中日英界面。所以要代码根界面分离。
    公司不用D版软件的,唯有从 mysql + php下手。之前没用过,现在临时抱佛脚。
    就来请教各位啦。各位不要吝啬啊,给些绝招。呵呵。
    怎么只有surfchen(冲浪)给出例子?
      

  8.   

    贴个phplib_template.inc的例子
    <?php
        include_once("inc/page.class.php");
        page::useSESSION();
        if (!page::Sar("isLogined")) {
            header("location:login.php");
            exit();
        }
        $tpl = page::useTPL("template/manage");
        if (page::safeGet('frame') == "left") {
            $tpl->set_file("main", "left.html");
            $tpl->set_var("username", page::Sar('user'));
            switch (page::Sar('power')) {
                case 0 :
                $tpl->set_var("power", "管理员");
                break;
                case 1 :
                $tpl->set_var("power", "审核编辑");
                break;
                case 2 :
                $tpl->set_var("power", "编辑");
            }
            $tpl->pparse("mains", "main");
        } else {
            $tpl->set_file("main", "frame.html");
            $tpl->pparse("mains", "main");
        }
    ?>$tpl是模板类实例。模板文件:left.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    table {
    font-family: "宋体", "Arial";
    font-size: 12px;
    text-decoration: none;
    }
    a:link {
    font-family: "宋体", "Arial";
    font-size: 12px;
    color: #FFFFFF;
    text-decoration: none;
    }
    a:visited {
    font-family: "宋体", "Arial";
    font-size: 12px;
    color: #FFFFFF;
    text-decoration: none;
    }
    a:hover {
    font-family: "宋体", "Arial";
    font-size: 12px;
    color: #FF6600;
    text-decoration: none;
    }
    a:active {
    font-family: "宋体", "Arial";
    font-size: 12px;
    color: #FF6600;
    text-decoration: none;
    }
    -->
    </style>
    </head><body bgcolor="#006699" leftmargin="0" topmargin="0">
    <table width="145" height="19" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="165" height="13" bgcolor="#FFFFFF"><div align="center">用户名:{username}<br>
            权限为:{power} </div></td>
      </tr>
    </table>
    <br>
    <table width="145" height="147" border="1" cellpadding="0" cellspacing="0" bordercolordark="#006699" bordercolorlight="#FFFFFF">
      <tr> 
        <td height="14"><div align="center"><font color="#FFFFFF">请选择您要执行的操作</font></div></td>
      </tr>
      <tr>
        <td height="79" valign="top"><table width="100%" height="334" border="0" cellpadding="0" cellspacing="0">
            <tr> 
              <td height="21" bgcolor="#0099FF"><strong><font color="#FFFFFF">〓用户管理</font></strong></td>
            </tr>
            <tr> 
              <td height="22"><div align="center"><a href="manage.php?a=adduser" target="mainFrame">添加新用户</a></div></td>
            </tr>
            <tr> 
              <td height="21"><div align="center"><a href="manage.php?a=edituser" target="mainFrame">编辑用户</a></div></td>
            </tr>
            <tr> 
              <td height="21"> <div align="center"><a href="manage.php?a=deleteuser" target="mainFrame">删除用户</a></div></td>
            </tr>
            <tr> 
              <td height="21" bgcolor="#00CC66"><strong><font color="#FFFFFF">〓新闻管理</font></strong></td>
            </tr>
            <tr> 
              <td height="19"><div align="center"><a href="manage.php?a=insert" target="mainFrame">添加新闻</a></div></td>
            </tr>
            <tr> 
              <td height="20"><div align="center"><a href="manage.php?a=editnews" target="mainFrame">编辑新闻</a></div></td>
            </tr>
            <tr> 
              <td height="21"><div align="center"><a href="manage.php?a=deletenews" target="mainFrame">删除新闻</a></div></td>
            </tr>
            <tr> 
              <td height="21"><div align="center"><a href="manage.php?a=permit" target="mainFrame">新闻审核</a></div></td>
            </tr>
            <tr> 
              <td height="21" bgcolor="#999999"><strong><font color="#FFFFFF">〓系统配置</font></strong></td>
            </tr>
            <tr> 
              <td height="21"><div align="center">此功能尚未启用</div></td>
            </tr>
            <tr> 
              <td height="21">&nbsp;</td>
            </tr>
            <tr> 
              <td height="21">&nbsp;</td>
            </tr>
            <tr> 
              <td height="21">&nbsp;</td>
            </tr>
            <tr> 
              <td height="21">&nbsp;</td>
            </tr>
            <tr> 
              <td height="21">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
      <tr> 
        <td height="26" valign="top"><div align="center"><a href="login.php?a=logout" target="_parent">退出登陆</a> 
          </div></td>
      </tr>
      <tr> 
        <td height="18"><div align="center">div></td>
      </tr>
    </table>
    </body>
    </html>
      

  9.   

    surfchen(冲浪) 兄的很简洁啊。
    有没更多的这样的例子啊?
      

  10.   

    phpwind 论坛的又是怎样设计的?
    还是看不懂的说。
      

  11.   

    搜索一下phplib教程,一会就学会了。
      

  12.   

    推荐用Brian Lozier写的这个微型模板,模板文件用 *.php 既可以实现"分离" 
    还可以在模板中应用php的功能这里有翻译:
    http://www.phpe.net/articles/384.shtml
      

  13.   

    个人认为比,FastTemplate,phplib template,SMARTY 好
      

  14.   

    love01px()说的这个确实很不错!
      

  15.   

    最简单的模板工具,smarttemplate.捷径是没有的
      

  16.   

    试试DedeCms里的模板类
    inc_dedetag.php
    <?
    require_once("inc_dedetag.php");
    $CDTag = new DedeTag();
    $ctp = new DedeTagParse();
    $ctp->LoadTemplate("test2.html");
    echo "----------------------------\r\n";
    echo "模板test2.html中包含的标签信息:\r\n";
    echo "----------------------------<font color='blue'>\r\n";
    foreach($ctp->CTags as $CDTag)
    {
    if($CDTag->CAttribute->Count!=-1)
    {
    echo "{".$ctp->NameSpace.":".$CDTag->TagName;
    foreach($CDTag->CAttribute->Items as $key=>$value)
    {
    if($key!="tagname")
    echo " $key=\"$value\"";
    }
    if($CDTag->InnerText!="")
    echo "}".$CDTag->InnerText."{".$ctp->NameSpace."}".
    "\r\n在模板中起始位置:".$CDTag->StartPos." 结束:".$CDTag->EndPos."\r\n";
    else
    echo "/>\r\n在模板中起始位置:".$CDTag->StartPos." 结束:".$CDTag->EndPos."\r\n";
    }
    }
    echo "</font>----------------------------\r\n";
    //把第一个标签取代为
    $ctp->Assign(0,"[文章的标签的取代内容]");
    //把第三个标签取代为
    $ctp->Assign(1,"[把第二个标签的取代内容!!!!!!!!!!!!!!!]");
    //把第三个标签取代为
    $ctp->Assign(2,"[把第三个标签的取代内容:::::::::::::::]");
    $CDTag = $ctp->GetTag("other");
    $restr = $CDTag->GetAtt("aaa");
    $ctp->Assign($ctp->GetTagID("other"),"[".$restr."]");
    echo "解析后的内容:\r\n";
    echo "----------------------------<font color='red'>\r\n";
    echo $ctp->Display();
    ?>test2.html文件
    --------------------------
    1234567890
    {dede:art num='3'}开始<b>粗体</b>结束{/dede}--
    1234567890
    {dede:list num="3"/}--
    1234567890
    {dede:spec num="4" 关键字="美女"/}--
    1234567890
    {dede:other num=3 aaa="好人好人好好人人"/}
    1234567890这个类似XML的风格,还可以自定义标记的属性,强哪
      

  17.   

    看来我也得去用公用的模板了。就从前面几位仁兄推荐的模板中选一个吧。
    但有个问题是,我看了几个论坛的源码。他们也是php代码跟html界面分离开的。
    但他们整个程序里都没有出现过 “= new Template” 这样的字眼。
    他们是怎样调用的呢?
    就像如下代码,不知道是那句调用了模板,刚学还看不懂。不好意思。
    希望没侵犯作者版权:)。
    <?php$wind_in='hm';
    require_once('./global.php');
    include_once(R_P.'data/bbscache/level.php');if($groupid!='guest'){
    $lastlodate=get_date($winddb['thisvisit']);
    $level=$ltitle[$groupid];
    }
    unset($lneed,$lpic);include_once(R_P.'data/bbscache/index_cache.php');
    if($notice_A){
    $NT_A=array_shift($notice_A);
    $NT_A['startdate']=get_date($NT_A['startdate'],'m-j G:i');
    $notice="<a href='notice.php?fid=$NT_A[fid]#$NT_A[aid]'>$NT_A[subject]($NT_A[startdate])</a>";
    }else{
    $notice='';
    }$forumdb=$catedb=array();unset($tposts);
    if(is_numeric($cateid)){
    $cateinfo=$db->get_one("SELECT style FROM pw_forums WHERE fid='$cateid'");
    if(!empty($cateinfo['style']) && file_exists(R_P."data/style/$cateinfo[style].php")){
    $skin=$cateinfo['style'];
    }
    $threadcate=" AND(fid='$cateid' OR fup='$cateid')";
    } else{
    $threadcate="";
    }require_once('./header.php');$c_htm=0;
    $cmsadd=$db_showcms ? '' : "AND cms!='1'";$topics=$article=$tposts=0;
    $query = $db->query("SELECT fid, fup, type,logo,name, descrip,forumadmin,tpost,topic,article,subtopic,lastpost,allowhtm,password,allowvisit,f_type,cms FROM pw_forums  WHERE ifsub='0' $cmsadd $threadcate ORDER BY vieworder");
    while($forums = $db->fetch_array($query)){
    if($forums['type']==='category'){
    if(strpos($deploy,"\t".$forums['fid']."\t")===false){
    $forums['deploy_img']='fold';
    }else{
    $forums['deploy_img']='open';
    $forums['tbody_style']='display:none;';
    }
    if($forums['forumadmin']){
    $forumadmin=explode(",",$forums['forumadmin']);
    foreach($forumadmin as $key => $value){
    if($value){
    if ($key==10) {$forums['admin'].='...'; break;}
    $forums['admin'].="<a href=profile.php?action=show&username=".rawurlencode($value)." class=cfont>$value</a> ";
    }
    }
    }
    $forums['name']=preg_replace("/\<(.+?)\>/eis","",$forums['name']);
    $catedb[]=$forums;
    } elseif($forums['type']==='forum'){
    if(empty($forums['password']) && (empty($forums['allowvisit']) || strpos($forums['allowvisit'],','.$groupid.',')!==false)){
    list($f_a,$forums['au'],$f_c,$forums['ft'])=explode("\t",$forums['lastpost']);
    $forums['pic'] = $winddb['lastvisit']<$f_c && ($f_c+172800>$timestamp) ? 'new' : 'old';
    $forums['newtitle']=get_date($f_c);
    $forums['t']=substrs($f_a,21);
    } else{
    if($forums['f_type']==='hidden'){
    continue;
    }
    $forums['pic']="lock";
    }
    $forums['topics']=$forums['topic']+$forums['subtopic'];
    $article+=$forums['article'];
    $topics+=$forums['topics'];
    $tposts+=$forums['tpost'];
    $forums['allowhtm']==1 && $c_htm=1;
    if($db_indexfmlogo==2){
    $forums['llogo']=$forums['logo']!='' ? "<img align=left src=$forums[logo] border=0>":'';
    } elseif($db_indexfmlogo==1){
    $forumlogofile="$imgpath/$stylepath/forumlogo/$forums[fid].gif";
    file_exists($forumlogofile) && $forums['llogo']="<img align=left src='$forumlogofile' border=0>";
    }
    $adminarray=explode("\t",$forums['forumadmin']);
    if($adminarray[0]){
    $forumadmin=explode(",",$adminarray[0]);
    foreach($forumadmin as $key => $value){
    if($value){
    if(!$db_adminshow){
    $forums['admin'].="<a href=profile.php?action=show&username=".rawurlencode($value).">$value</a> ";
    } else{
    $forums['admin'].="<option value='$value'>$value</option>";
    }
    }
    }
    $db_adminshow && $forums['admin'].='</select>';
    }
    $forumdb[$forums['fup']][]=$forums;
    }
    }
    $db->free_result($query);
    unset($forums);/**
    * Share union
    */
    if($db_indexmqshare){
    $sharelink="<marquee scrolldelay=100 scrollamount=4 onmouseout='if (document.all!=null){this.start()}' onmouseover='if (document.all!=null){this.stop()}' behavior=alternate>$sharelink</marquee>";
    }
    if(strpos($deploy,"\t".info."\t")===false){
    $cate_img='fold';
    }else{
    $cate_img='open';
    $cate_info='display:none;';
    }
    /**
    * oline users
    */Update_ol();
    @include_once(R_P.'data/bbscache/olcache.php');
    $usertotal=$guestinbbs+$userinbbs;if($windid==$manager || $usertotal<2000){
    if($online){
    $online1=$online;
    Cookie('online1',$online);
    }
    if($db_indexonline && $online1!='no'){
    $doonlinefu=1;
    } elseif($online1=='yes'){
    $doonlinefu=1;
    }
    }
    $showgroup=explode(",",$db_showgroup);
    @extract($db->get_one("SELECT * FROM pw_bbsinfo WHERE id=1"));
    if($tdtcontrol!=$tdtime){
    if($db_hostweb==1){
    $db->update("UPDATE pw_bbsinfo SET yposts='$tposts', tdtcontrol='$tdtime' WHERE id=1");
    $db->update("UPDATE pw_forums SET tpost=0 WHERE tpost<>'0'");
    }
    if(file_exists(R_P.'data/bbscache/ip_cache.php')){
    @unlink(R_P.'data/bbscache/ip_cache.php');
    }
    }
    /**
    * update posts hits
    */
    if($c_htm || $db_hithour){
    $db_hithour==0 && $db_hithour=4;
    $hit_wtime=$hit_control*$db_hithour;
    if($hit_wtime>24)$hit_wtime=0;
    $hitsize=@filesize(R_P."data/bbscache/hits.txt");
    if(($timestamp-$hit_tdtime)>$hit_wtime*3600 || $hitsize>1024){
    require_once(R_P.'require/hitupdate.php');
    }
    }
    if($higholnum<$usertotal){
    $db->update("UPDATE pw_bbsinfo SET higholnum='$usertotal',higholtime='$timestamp' WHERE id=1");
    $higholnum=$usertotal;
    }
    if($hposts<$tposts){
    $db->update("UPDATE pw_bbsinfo SET hposts='$tposts' WHERE id=1");
    $hposts=$tposts;
    }
    $mostinbbstime=get_date($higholtime);
    if($db_onlinelmt!=0 && $usertotal>=$db_onlinelmt && !$ol_offset){
    Cookie('ol_offset','',0);
    Showmsg('most_online');
    }
    $rawnewuser=rawurlencode($newmember);
    require_once PrintEot('index');footer();
    ?>
      

  18.   

    我还是用Smarty,呵呵,虽然很多人都对这个庞大的家伙很不屑(我曾经在刚入门的时候也不屑过)~但是能得到Smarty.php.net这个域名这样的认可,你不能不说是一种成就~~~功能不但强大,而且灵活,要繁则繁,要简则简~~写插件也是非常方便~~
    PS:我现在用的Smarty是309KB大小,虽然可能比起别的类来说是大了点~~不过那么多功能,你还能要求它再小一点么?要知道我现在用的PEAR包都有1.8M了~~~轻量与功能强大永远是矛盾的,所谓“即轻量,又功能强大”那只不过可能找到了一个平衡点而已~~~坚决反对“编程纯种论”~~
      

  19.   

    用phpbb中带的模板,不大又实用
      

  20.   

    php:
    <?php
    $title="abc";
    include("abc.htm");
    ?>abc.htm
    <html>
    <head>
    <title><?$title?></title>
    </head>
    </html>应该是最简单的代码和页面分离了吧...呵呵.不过建议还是学一下模板,SMARTY的一些常用的功能,一天就能学会,用起来绝对帮你省了那一天的时间.
      

  21.   

    <title><?$title?></title>
    应该改为
    <title><?=$title?></title>
      

  22.   

    用Smarty解决代码后置问题吧。