ทำได้นะคับ
แต่แนะนำให้แยก template ออกมาอีกไฟล์เลย
<html>
<head></head>
<body>
<!-- header -->
<!-- sidebar -->
##ARTICLE##
<!-- footer-->
</body>
</html>
ตรงที่เ็ป็นสีๆ ก็ใส่ html ปกติของเว็บคุณไป ยกเว้นสีแดง ##ARTICLE## ก็พิมพ์ทิ้งไว้ตรงที่อยากจะให้บทความแสดง
เก็บไฟล์ template ไว้ใน dir ต่างหากอีก dir นึง ชื่อไรก้ได้ สมมุติเป็นชื่อ 'include'
ไฟล์ txt ของบทความก็เก็บแยกไว้อีก dir นึง อาจใช้ชื่อว่า 'article'
ทีนี้หน้าที่จะแสดงจริงก็เรียกแบบนี้
<?php
$template = file_get_contents('include/template.html'); // ใส่ที่อยู่ template
$article = file_get_contents('article/001.txt'); // ใส่ที่อยู่ของบทความที่จะแสดง (ต้องเป็น html อยู่แล้ว)
$page = str_replace('##ARTICLE##',$article,$template); // แทนที่ ##ARTICLE## ด้วยบทความ
echo $page; // แสดงหน้าที่สมบูรณ์แล้ว
?>
เวลาจะออกแบบหน้าตา หรือใส่อะไรเพิ่ม อย่างพวก tracker พวกนี้ ก้ไปแก้ใน template เอาเลย
แค่นี้แหละคับ วิธีบ้านๆ ผมไม่ค่อยเชี่ยวชาญ แต่ก็พอนึกออก
หวังว่าน่าจะช่วยได้นิดนึงนะคับ
ผมลองทำดูแล้วครับ แต่ทำได้ทีละไฟล์เหรอครับ หรือผมทำอะไรผิด
ผมมี 3 Folder
1.article มีบทความ .txt 1อยู่4ไฟล์
3-things-to-do-before-considering-automobile-buying-and-financing.txt
4-tips-for-buying-seized-vehicles-at-police-auctions.txt
4-tips-to-buy-cheap-repossessed-cars-at-auto-auctions.txt
5-common-mistakes-to-avoid-when-buying-a-used-car.txt
2.include มี template.html
3.html เก็บไฟล์ .html
index.php
<?php
$template = file_get_contents('include/template.html'); // ใส่ที่อยู่ template
$article = file_get_contents('article/3-things-to-do-before-considering-automobile-buying-and-financing.txt); // ใส่ที่อยู่ของบทความที่จะแสดง (ต้องเป็น html อยู่แล้ว)
$page = str_replace('##ARTICLE##',$article,$template); // แทนที่ ##ARTICLE## ด้วยบทความ
echo $page; // แสดงหน้าที่สมบูรณ์แล้ว
?>
ก็แสดงสมบูรณ์ครับ แต่ไม่ gen อยู่ใน folder html