php生成靜態
❶ php程序如何批量生成靜態頁
PHP生成靜態頁最近作的一個項目中用到了兩種用PHP生成靜態頁面的方法,回專想起當初自己還不知屬道如何生成靜態頁面的迷惘,以及看不懂高手寫的文章的痛苦,覺得自己有必要站出來為還不知道如何生成靜態頁的phper寫一個通俗點文章,以幫助他們盡快掌握這個好東西。兩種方法簡單說明如下:1. 使用文件函數得到靜態頁面的模板字元串,然後用str_replace函數將需要替換的東西替換了再寫入到新的文件中。2. 利用PHP的輸出控制函數(Output Control)得到靜態頁面字元串,再寫入到新的文件中。
❷ PHP 如何生成靜態圖片
<?php
$im = ImageCreate(200,200);$red = ImageColorAllocate($im,0xFF,0x00,0x00);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$ys1 = ImageColorAllocate($im,0xE9,0xB1,0x50);
$ys2 = ImageColorAllocate($im,0x98,0x25,0xCB);
$ys3 = ImageColorAllocate($im,0x40,0x88,0x47);ImageFilledRectangle($im,50,50,150,150,$black);
//點
for($i=0;$i<300;$i++){
ImageSetPixel($im,rand(1,200),rand(1,200),$white);
}
//虛線
for($i=0;$i<10;$i++){
ImageDashedLine($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//線
for($i=0;$i<10;$i++){
ImageLine($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//矩形框
for($i=0;$i<3;$i++){
ImageRectangle($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//矩形面
for($i=0;$i<2;$i++){
ImageFilledRectangle($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//多邊形
$point = array(rand(1,200),rand(1,200),rand(1,200),rand(1,200),rand(1,200),rand(1,200));
ImagePolygon($im,$point,count($point)/2,$ys2);
ImageFilledPolygon($im,$point,count($point)/2,$ys2);
//弧線
ImageArc($im,rand(20,180),rand(20,180),rand(50,150),rand(50,150),rand(0,360),rand(0,360),$ys3);
//打字
ImageString($im,4,20,30,"add word",$ys3);
ImageTTFText($im,30,0,rand(0,50),rand(30,200),$ys3,'msyhbd.ttf',"添加文字");header('Content-Type:image/png');
ImagePNG($im);
?>
❸ php前台生成靜態頁面
給你舉個簡單的例子
2個文件
1個 temp.html 是模板文件
1個 test.php 是程序文件
在模板文件中有兩個{name} 和{age}標記
我們要通過程序文件,替換兩個標記並生成新的html文件
——————temp.html————————
<html>
<head><title>{name}的介紹</title></head>
<body>
{name},今年{age}歲了
</body>
</html>
———————test.php————————
<?php
$name = "小強";
$age = "14";
$new = "new1.html";//要生成的靜態頁面
$file = fopen("temp.html","rb");//打開模板
$temp = fread($file,filesize("temp.html"));//讀取模板內容
$temp = str_replace("{name}",$name,$temp);
$temp = str_replace("{age}",$age,$temp);//替換了兩個標記
fwrite(fopen($new,"wb"),$temp);//寫入靜態頁面
echo "生成成功!";
?>
這時候你看看是不是生成了new1.html
下面改進一下,批量生成
——————————test2.php————————————
<?php
$name = array("小強","小剛","小紅","小靜");
$age = array("14","17","15","14");
$file = fopen("temp.html","rb");//打開模板
$temp = fread($file,filesize("temp.html"));//讀取模板內容
for($i=0;$i<count($name);$i++){
$ok = "";
$ok = str_replace("{name}",$name[$i],$temp);
$ok = str_replace("{age}",$age[$i],$ok);//替換了兩個標記
$fp = fopen($i."_n.html","wb");//寫入靜態頁面
fwrite($fp,$ok);
fclose($fp);
}
?>
最後生成了
0_n.html
1_n.html
2_n.html
3_n.html
❹ php怎麼生成靜態頁面
利用模板。目前PHP的模板可以說是很多此賣埋了,有功能強大的smarty,還有簡單易用的smarttemplate等。它們每一種模板,都有一個獲取輸出內容的函數。我們配睜生成靜態頁面的方法,就是利用了這個函數。用這個方法的優點是,代碼比較清晰,可讀性好。
這里我用smarty做例子,說明如何生成靜態頁:
<?php
require("smarty/Smarty.class.php");
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//這里的 fetch() 就是獲取森螞輸出內容的函數,現在$content變數裡面,就是要顯示的內容了
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>
❺ PHP生成純靜態網頁。
是吧,現粗笑在生成html的網址 一般是兩種。
1.就是你上面說的,把PHP裡面的內容讀取一遍,再寫入到對應的html頁面裡面。這種有個問題就是刪除比較麻煩,操作io比較大 但是快。
2.偽靜態,根據web伺服器,按照規則顯示。實際上還是PHP文件 只是看起來是html 這種運用明凳友比較廣,推薦這種。激槐