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 这种运用明凳友比较广,推荐这种。激槐