2025-02-15

簡單演示PHP如何使用模板生成靜態頁面。


模板文件templets.htm:

<html>
  <head>
    <title>{title}</title>
  </head>
  <body>
    <p>Hello {hello}</p>
  </body>
</html>


 PHP文件代碼:

<?php

  $title = webjx;
  $hello = webjxcom!;
  $file = file_get_contents(templets.htm);
  $file = str_replace(array({title},{hello}),array($title,$hello), $file);
  echo $file;

?>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *