1. 程式人生 > >PHP自定義生成html網頁

PHP自定義生成html網頁

先來個預覽吧:

許多網頁並不是人們去專門修改的

而是通過php一鍵修改的

如 114G 等這些一鍵生成網頁的網站

 

和上篇文章原始碼( PHP自定義生成圖片——靜態)類似,不過在其某些地方進行了一些修改

解釋:

bootstrap             html UI;

bg                         背景圖片

demo.html           模板html

demo.php            主要檔案,修改文字,更改原始碼

index.html           主頁

shengcheng.html 生成介面

yulan.html             預覽的介面

 

demo.html

紅框圈出來的是程式碼更改的地方,通過demo.php實現修改文字

 

demo.php

<?php
/**
 * Created by PhpStorm.
 * User: 莫言情難忘
 * Date: 2018/5/15
 * Time: 20:29
 */
$title = $_GET['title']?$_GET['title']:"網頁標題";//html title
$biaoti   = $_GET['biaoti']?$_GET['biaoti']:"情書標題";//情書標題
$name = $_GET['name']?$_GET['name']:"它的名字";;//情書 他(她)的名字
$neirong  = $_GET['neirong']?$_GET['neirong']:"內容";//情書內容
$me = $_GET['me']?$_GET['me']:"自己名字";//情書 你的名字
$url = $_GET['url']?$_GET['url']:"背景音樂URL";;//背景音樂URL

$fp=fopen("demo.html","r");
$text=fread($fp,filesize("demo.html"));

$text = str_replace ("{replace_title}",$title,$text);
$text = str_replace ("{replace_biaoti}",$biaoti,$text);
$text = str_replace ("{replace_name}",$name,$text);
$text = str_replace ("{replace_neirong}",$neirong,$text);
$text = str_replace ("{replace_me}",$me,$text);
$text = str_replace ("{replace_url}",$url,$text);

fclose($fp);

//demo?title=網頁標題&biaoti=情書標題&name=他(她)的名字&neirong=情書內容&me=自己名字&url=背景音樂URL
$path = $me."and".$name.".html";
//新建空白檔案,將$str寫入
$handle=fopen($path,"w");
fwrite($handle,$text);
fclose($handle);
include 'index.php';

而demo.php通過讀取檔案,替換其中的文字就能輕鬆地實現生成html

測試網址:www.520mylove.com/biaobai

分享連結

連結: https://pan.baidu.com/s/1mJ__WsZx3-rVs_bPITK5xQ

提取碼: 6666

                                                                                                                       ————莫言情難忘

PS:模板檔案取自114G.com