ホームページ  >  記事  >  バックエンド開発  >  PHP は静的ページの HTML ページのコードを生成します_PHP チュートリアル

PHP は静的ページの HTML ページのコードを生成します_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:39:50677ブラウズ

  1. header(Content-type:text/html;charset=utf-8);
  2. if(!function_exists(file_get_contents)){ //システムに file_get_contents( ) function
  3. function file_get_contents($file){ //file_get_contents() 関数を自分で書きます
  4. $fp = fopen($file,r);
  5. $content = fread($fp,filesize($file));
  6. fclose($ fp);
  7. return $content;
  8. }
  9. }
  10. $tmp_file = template.html; //テンプレートファイル
  11. $content = file_get_contents($tmp_file); //
  12. $title = title; //テンプレート変数 title に置き換えられる値
  13. $text = text; //テンプレート変数 text に置き換えられる値
  14. $content = str_replace(<{title} >,$title,$content); / / テンプレート変数 title を置き換えます
  15. $content = str_replace(<{text}>,$text,$content); // テンプレート変数 text を置き換えます
  16. // echo $content; // 置き換えられたテンプレート ファイルの内容を表示します
  17. MakeHtml(news.html,$content);// 生成された静的ファイルの内容を news.html ファイルに書き込みます
  18. echo ファイルを表示< ;/a>;
  19. function MakeHtml($file,$content){
  20. $fp = fopen($file,w);
  21. fwrite($fp,$content) ;
  22. fclose($fp);
  23. }
  24. ?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/486247.html技術記事 ?php header(Content-type:text/html;charset=utf-8); if(!function_exists(file_get_contents)){ //システムに file_get_contents() 関数がない場合 function file_get_contents($file){ //自分で書いてください..