ȨתأתʱԳʽԭʼϢ
ĳ:http://www.otm.cn ߣMatrix@Two_Max


ȻعһЩĸ

һPHPű붯̬ҳ档

PHPűһַ˽ű򣬿ͨǶȷHTMLļϣҲ࣬װʽģķʽûдԺַʽĻԭġɿͻĳһҳ桡----->WEBָӦűд----->ű----->ɷָPHPԽűнγHTMLʽ---->HTML԰ķʽظɴ˲ѿҳ淢͵PHPͲˣѱתΪHTML䡣ͻΪһ̬ļʵϲûļPHPӦҳ棬Ȼͻҳ洦ʽΪ̬ҳ桱

̬ҳ档

̬ҳָڷȷʵڵĽHTMLԼJSCSSȿͻнűҳ档Ĵʽǡɿͻĳһҳ桡---->WEBȷϲĳһҳ桡---->WEBҳ԰ʽݻһ̣ǶԱһ¶̬ҳ棬ɷ̬֡ҳWEBPHPнͨݿ⣬ݿȡȻγHTMLϢ̬ҳ棬ݿ⣬ֱӷͣɴѹ߷ṩҳٶȺվٶȡȱǣ̬ܶضдϱȷʵڸļ

ģ弰ģ

ģ弴δhtmlļ磺

temp.html

  Code:    
<HTML>
  <TITLE>{ title }</TITLE>
  <BODY>
     this is a { file } file's templets
  </BODY>
</HTML> 
 


PHP

templetest.php


  Code:    
  $title = "PHP߲ģ";
  $file   = "TwoMax Inter test templet,
authorSheyi";

$fp          = fopen ("temp.html","r");
  $content  = fread ($fp,filesize ("temp.html"));
  $content .= str_replace ("{ file }",$file,$content);
  $content .= str_replace ("{ title }",$title,$content);

  echo $content;
?> 
 

ģPHPűóĽ(content)ģĴ̡ͨģࡣĿǰеģphplibsmartyfastsmartyȵȡģԭͨΪ滻ҲЩԱϰ߽жϣѭȴŽģļУýദӦΪblock˵ΪһѭPHPűָѭѭȣģʵʩЩ


ˣԱȹ̬ҳ붯̬ҳԵӣǾ˵˵PHPɾ̬ļ


PHPɾ̬ҳ沢ָPHPĶ̬HTMLҳ棬ָPHPHTMLҳ档ͬʱΪHTMLĲдԣǴHTML޸ģɾɼɡ(ȻҲѡ޸ģΪɾÿݣЩòʧ)

ԹùPHPļPHP FANS֪PHPһļfopenļļڣԴ⼴PHPHTMLļۻֻҪHTMLļļдȨ(Ȩ޶0777)ɴļUNIXϵͳԣWinϵͳ뿼ǡΪ޸һ䣬ָtestĿ¼һΪtest.htmlľ̬ļ


  Code:    
  $title = "ʲģ";
  $file   = "TwoMax Inter test templet,
authorMatrix@Two_Max";

$fp          = fopen ("temp.html","r");
  $content  = fread ($fp,filesize ("temp.html"));
  $content .= str_replace ("{ file }",$file,$content);
  $content .= str_replace ("{ title }",$title,$content);

  // echo $content;
  
  $filename = "test/test.html";
  $handle    = fopen ($filename,"w"); //ļָ룬ļ
  /*
ļǷ񱻴ҿд
  */
  if (!is_writable ($filename)){ 
     die ("ļ".$filename."дԺԣ");
  }
  if (!fwrite ($handle,$content)){  //Ϣдļ
     die ("ļ".$filename."ʧܣ");
  } 
  fclose ($handle); //رָ
  
  die ("ļ".$filename."ɹ");
?>   
 


ʵӦгο

һб⣺

ݿдֶΣ¼ļÿһļԶɵļݿ⣬Ƽ£ָֻž̬ļָļеĸҳ漴ɡPHPбΪַҳʱ滻ַɡ磬ҳзбı{ articletable }PHPļУ


  Code:    
  $title = "ʲģ";
  $file   = "TwoMax Inter test templet,
authorMatrix@Two_Max";

$fp          = fopen ("temp.html","r");
  $content  = fread ($fp,filesize ("temp.html"));
  $content .= str_replace ("{ file }",$file,$content);
  $content .= str_replace ("{ title }",$title,$content);
  
  //  бʼ
  $list = '';
  $sql = "select id,title,filename from article";
  $query = mysql_query ($sql);
  while ($result = mysql_fetch_array ($query)){ 
     $list .= ''.$result['title'].'
';
  }
  $content .= str_replace ("{ articletable }",$list,$content);
  
  //б
  // echo $content;
  
  $filename = "test/test.html";
  $handle    = fopen ($filename,"w"); //ļָ룬ļ
  /*
ļǷ񱻴ҿд*/
  if (!is_writable ($filename)){ 
     die ("ļ".$filename."дԺԣ");
  }
  if (!fwrite ($handle,$content)){  //Ϣдļ
     die ("ļ".$filename."ʧܣ");
  } 
  fclose ($handle); //رָ
  
  die ("ļ".$filename."ɹ");
?> 
 

ҳ⡣

ָҳʱÿҳ20ƪĳƵб¾ݿѯΪ45ͨѯõ²1ҳ2ÿҳƪڶfor ($i = 0; $i < allpages; $i++)ҳԪػȡɣڴѭִСͬǣdie ("ļ".$filename."ɹ";ȥŵѭʾΪ佫ִֹС


  Code:   
  $fp          = fopen ("temp.html","r");
  $content  = fread ($fp,filesize ("temp.html"));
  $onepage  = '20';
  $sql          = "select id from article where channel='$channelid'";
  $query      = mysql_query ($sql);
  $num        = mysql_num_rows ($query);
  $allpages   = ceil ($num / $onepage);

  for ($i = 0;$i<$allpages; $i++){ 
     if ($i == 0){ 
        $indexpath = "index.html";
      } else { 
        $indexpath = "index_".$i."html";
      }
     
$start = $i * $onepage;
     $list    = '';
     $sql_for_page = "select name,filename,title from article where channel='$channelid' limit $start,$onepage";
     $query_for_page = mysql_query ($sql_for_page);
     while ($result = $query_for_page){ 
        $list .= ''.$title.'
';
      }
     
     $content = str_replace ("{ articletable }",$list,$content);

     if (is_file ($indexpath)){ 
        @unlink ($indexpath); //ļѴڣɾ
      }

     $handle    = fopen ($indexpath,"w"); //ļָ룬ļ
     /*
   ļǷ񱻴ҿд
     */
     if (!is_writable ($indexpath)){ 
        echo "ļ".$indexpath."дԺԣ"; //޸Ϊecho
      }
     if (!fwrite ($handle,$content)){  //Ϣдļ
        echo "ļ".$indexpath."ʧܣ"; //޸Ϊecho
      } 
     fclose ($handle); //رָ
  }

  fclose ($fp);
  die ("ɷҳļɣɲȫļȨϵͳɣ");

?> 

 
˼·ˣɣ飬ҳָȿҳм롣

ʵϵͳ̵Удǣ붯̬ҳ治֮ͬעĵطкܶࡣ˼·ˣɾһá


