如何用phplib直接生成静态页面???

Arbow 2002-07-07 09:59:09
我搜索过相关帖子,有一篇是将动态页面生成静态页面。不过如果要用phplib直接把提交的新闻生成静态页面,文章的连接地址是http://xxx.xxx/xxx.htm这样的形式,不是http://xxx.xxx/xxx.php?id=xx 然后转向静态页面,该怎样做???请php高手们指教,最好有相关代码。一定给分。
...全文
39 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
limenghao2 2002-07-07
  • 打赏
  • 举报
回复
接上:
?>
<html>
<head>
<title>长沙房地产信息网</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../../include/common.css" type="text/css">
<script LANGUAGE="javascript">
function aa(){
if(document.form1.title.value==''){
alert('文章标题不能为空!');
return false;
}
if (document.form1.keyword.value==''){
alert('标题关键字不能为空!');
return false;
}
if(document.form1.text.value==''){
alert('文章正文不能为空!');
return false;
}
document.form1.target='_blank';
document.form1.action='asdfsdf.php';
document.form1.submit();
}
function ba(){
if(document.form1.title.value==''){
alert('文章标题不能为空!');
return false;
}
if (document.form1.keyword.value==''){
alert('标题关键字不能为空!');
return false;
}
if(document.form1.text.value==''){
alert('文章正文不能为空!');
return false;
}

var s=document.form1.text.value;
var pl=/[\f\r\t\v' ']+/g;
s=s.replace(pl,"");
var pl=/[\n]+[\s]*/g;
s=s.replace(pl,"</p>\n<p>  ");
s="\n<p>  "+s+"</p>\n";
document.form1.article.value=s;
document.form1.action=location.href;
document.form1.submit();
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<table width="564" border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td width="10"><img src="../images/right_top1.jpg" width="17" height="22"></td>
<td bgcolor="#595959"><span class="gray">后台管理-家居装饰管理系统-</span><span class="white">装饰知识发布模块:</span></td>
<td width="11" bgcolor="#595959"></td>
</tr>
<tr>
<td width="10"><img src="../images/right_top2.jpg" width="17" height="11"></td>
<td background="../images/right_bg4.jpg"></td>
<td width="11"><img src="../images/right_top3.jpg" width="11" height="11"></td>
</tr>
<tr>
<td width="5" background="../images/right_bg1.jpg"> </td>
<td width="535" valign="top">
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" class="gray2">
<tr>
<td width="2"><img src="../images/right_logo5.jpg" width="2" height="15"></td>
<td width="117" valign="middle" align="center" background="../images/right_bgline1.jpg">
装饰知识提交
</td>
<td width="234"><img src="../images/right_logo4.jpg" width="2" height="15"></td>
<td width="58"> </td>
<td width="103"> </td>
</tr>
<tr align="center">
<td colspan="5" valign="top" bgcolor="#F4F4F4" style="padding:30,0,0,0">
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" style="line-height:30px">
<form method="post" enctype="multipart/form-data" name="form1"><tr>
<td width="16%">文章标题:</td>
<td width="84%">
<input type="text" name="title" class="smallInput" size="35">
  关键字:
<input type="text" name="keyword" class="smallInput" size="10"></td>
</tr>
<tr>
<td width="16%" valign="top">文章正文:</td>
<td width="84%" valign="top">
<textarea name="text" style="border:black 1 soild;overflow-x:hidden" cols="60" rows="15"></textarea>
</td>
</tr>
<tr>
<td width="16%" valign="top">相关图片:</td>
<td width="84%" valign="top" style="padding-top:5px;"><input name="img" type="file" size="35">
</td></tr>
<tr>
<td width="16%" height=18> </td>
<td width="84%" align=right style="padding-top:15px;">   
<input type="reset" name="reset" value="重 写" class="buttonface">
<input type="button" name="Submit" value="提 交" class="buttonface" ONCLICK="ba()">
<input type="hidden" name="sfd" value="kk">
<input type="hidden" name="article">    
</td></tr> </form>
</table>
<br>
  <a href="<?print $PHPSELF?>?today='today'"><span class="red">查看今天提交的新闻:</span></a>
               查看
<select name="select" onchange="var url='knowledge.php?month='+this.options[this.selectedIndex].value; window.location=url">
<option value=null>选择月份</option>
<option value="1月">一月份</option>
<option value="2月">二月份</option>
<option value="3月">三月份</option>
<option value="4月">四月份</option>
<option value="5月">五月份</option>
<option value="6月">六月份</option>
<option value="7月">七月份</option>
<option value="8月">八月份</option>
<option value="9月">九月份</option>
<option value="10月">十月份</option>
<option value="11月">十一月</option>
<option value="12月">十二月</option>
</select>
提交的新闻 <br>
<table width="96%" height="1" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td style="border-top:1 solid black"></td>
</tr>
</table><br>

<table width="96%" border="1" align="center" cellpadding="1" cellspacing="0" class="black">
<form name="form3" method="post" action="">
<tr>
<td width="50%" align="center" class="bluel">知 识 标 题</td>
<td width="20%" align="center">提交日期</td>
<td width="10%" align="center">删 除</td>
<td width="20%" align="center">重新提交</td>
</tr>
<?for($r=0;$r<$tod_limit;$r++){?>
<tr>
<td height="19"> <a href='<?print $tod_link_id[$r];?>' class=blackl target=_blank><?print $tod_title[$r]?></td>
<td align="center"><?print $tod_post_time[$r]?></td>
<td align="center"><img src="../images/cut.gif" width="19" height="22" style="cursor:hand" onclick="javascript:if(confirm('该记录一旦删除将无法恢复,你真的要删除吗?')){window.location='knowledge_del.php?del_id=<?print $tod_id[$r];?>'}"></td>
<td align="center"><input type="button" name="Submit2" value="重新提交" ONCLICK="window.location='knowledge_reload.php?re_id=<?print $tod_id[$r];?>'">
</td>
</tr>
<?}?>
<tr align="right">
<td colspan="4">共<span class=red><?print $tod_count;?></span>条记录   <?print $linked;?>    </td>
</tr> </form>
</table></td>
</tr>
</table>
</td>
<td width="16" background="../images/right_bg3.jpg"> </td>
</tr>
<tr>
<td width="10"><img src="../images/right_bot1.jpg" width="17" height="10"></td>
<td width="535" background="../images/right_bg2.jpg"></td>
<td width="11"><img src="../images/right_bot2.jpg" width="11" height="10"></td>
</tr>
</table>
</body>
</html>

这里的生成的页面放到另一个文件夹,而需更新链接的页面中要帮好<!-- ** Start--><!-- ** End-->的标签,以用正则判断,然后替换,大致原理如此,如还有疑问的,QQ:27335078联系,

个人意见,仅供参考,
limenghao2 2002-07-07
  • 打赏
  • 举报
回复
1、其实用phplib最大的好处是代码简便实用,可以用它来做到静态页面和动态页面分开使用,即在一个静态页面中需用到php代码的地方用一个标记标明,而在php页面中则替换掉这个标记,这种好处是改版美工的时候程序不需重新设计,如:
  静态页面:<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" valign="top"><img src="images/title_news.gif" width="183" height="20"></td>
</tr>
<tr>
<td width="6"></td>
<td width="171" valign="top" style="border-left:1px solid #74726A;border-right:1px solid #74726A;padding:5,5,5,8;line-height:20px">
<!-- BEGIN news --> //注意这里
<span class=f7>●</span> {hotnews}<br>//注意这里
<!-- END news -->
<div align=right><a href="http://www.0731fdc.com/news/fc/" target="_blank"><img src="images/btn_more.gif" width="49" height="23" border="0"></a></div> </td>
<td width="6"></td>
</tr>
</table>

  php页面:<?
require("php/template.inc");
 $hotlist = $info_hot.$info_hot_b;

$root = "html";
$t = new Template(".");
$t -> set_root($root);
$t -> set_file("fHandle","index.htm");
 $t -> set_var("hot_list","$hotlist");//这里完成替换

$t -> parse("out","fHandle");
$t -> p("out");

2、可以在后台提交时(如新闻)直接生成成静态页面,生成链接地址和标题存到数据库,同时将所有有该项横向链接的页面更新,如后台提交代码:

<? session_start();
require("comman1.php");
require("jjzs/page_start.php");
require("jjzs/function.php");

if ($sfd=='kk'){

$sql_a = "select * from home_news order by id desc";
$DB -> query($sql_a);
$DB -> next_record();
$post_date = date("Y-m-d");
$date = date("Ymd");

$target_id = date("His"); //链接地址
$target_page="../knowledge/".$date."/".$target_id.".phtml";
$create_link_id = "http://home.0731fdc.com/knowledge/".$date."/".$target_id.".phtml";

if (!@dir("../knowledge/".$date)){
mkdir("../knowledge/".$date);
}
$dir = "../knowledge/".$date;

############### 上传图片 ################
if($img_name!="")
{
$retval="";
$pt=strrpos($img_name, ".");
$filen=date("His");
if ($pt)
$retval=substr($img_name, $pt+1, strlen($img_name) - $pt);

if((strtolower($retval)!="jpg")&&(strtolower($retval)!="gif"))
{ # 判断图片类别是否正确
echo "<script>";
echo "alert(\"你使用了不合法的图片类型!\");</script>";
exit();
}

# 保存图片到相应目录
$img_name=$filen.".".$retval;
copy($img,$dir."/".$img_name);

# 处理图片大小
$old_size=getimagesize($dir."/".$img_name);
$m_rate=$old_size[1]/$old_size[0];
$n_y=200*$m_rate;
$resize_cmd="mogrify -geometry 200x".$n_y."> ".$dir."/".$img_name;
exec(EscapeShellCmd($resize_cmd));
@exec("chmod 757 ".$img_name);
} //图片上传结束

######## 插入数据库记录 ##########
$id_old = $DB -> f("id");
$id = $id_old+1;
$update_sql = "insert into home_news(id,title,text,link_id,post_time,images) values('$id','$title','$s','$create_link_id',sysdate,'$img_name_s')";
$t = $DB -> query($update_sql);

########### 更新首页面装饰知识栏目 ############
update_page("../index_two.phtml","装饰知识","select * from home_news order by post_time desc",10,'');

########### 更新首页面新闻栏目 ############
update_page("../index_one.phtml","家居新闻","select title,link_id from news_main where cate like '%装饰装修%' order by post_date desc",10,"http://news.0731fdc.com/decorate");

$fn = "../knowledge/info.phtml";
$fp=fopen($fn,"r");
$main_str=fread($fp, filesize($fn));
fclose($fp);

######## 提取相关知识标题 ########
$C_key_sql = "select count(id) from home_news where title like '%$keyword%' order by post_time desc";
$DB -> query($C_key_sql);
$DB -> next_record();
$count = $DB -> f("count(id)");
$key_sql = "select title,link_id from home_news where title like '%$keyword%' order by post_time desc";
$DB -> query($key_sql);
for ($w=0;$w<6;$w++){
if ($w<$count){
$DB -> next_record();
$link_id[$w] = $DB -> f("link_id");
$title_kn .= "<img src='/images/red_logo.jpg' width=4 height=4> <a href='".$link_id[$w]."' class=blackl>".$DB -> f("title")."</a><br>";
}
}
$title_str = "<!-- 相关知识 Start-->.*<!-- 相关知识 End-->";
ereg($title_str,$main_str,$regs);
$main_str = str_replace($regs[0],"<!-- 相关知识 Start-->".$title_kn."<!-- 相关知识 End-->",$main_str);

######## 提取热点推荐标题 ########
$C_hot_sql = "select count(id) from home_news where title like '%新潮%' or title like '%时尚%' or title like '%装修%' or title like '%装饰%' or title like '%流行%' order by post_time desc";
$DB -> query($C_hot_sql);
$DB -> next_record();
$count_hot = $DB -> f("count(id)");
$hot_sql = "select title,link_id from home_news where title like '%新潮%' or title like '%时尚%' or title like '%装修%' or title like '%装饰%' or title like '%流行%' order by post_time desc";
$DB -> query($hot_sql);
for ($i=0;$i<6;$i++){
if ($i<$count_hot){
$DB -> next_record();
$link_id_hot[$i] = $DB -> f("link_id");
$title_kn_hot .= "<img src='/images/red_logo.jpg' width=4 height=4> <a href='".$link_id_hot[$i]."' class=blackl>".$DB -> f("title")."</a><br>";
} }
$title_str = "<!-- 热点推荐 Start-->.*<!-- 热点推荐 End-->";
ereg($title_str,$main_str,$regs);
$main_str = str_replace($regs[0],"<!-- 热点推荐 Start-->".$title_kn_hot."<!-- 热点推荐 End-->",$main_str);

########## 生成子页面 ##########
$title_str="<!-- 文章标题 Start-->.*<!-- 文章标题 End-->";
ereg($title_str,$main_str,$regs);
$main_str = str_replace($regs[0],"<!-- 文章标题 Start-->".$title."<!-- 文章标题 End-->",$main_str);

$date_str="<!-- 发布日期 Start-->.*<!-- 发布日期 End-->";
ereg($date_str,$main_str,$regs);
$main_str = str_replace($regs[0],"<!-- 发布日期 Start-->".$post_date."<!-- 发布日期 End-->",$main_str);

$text_str="<!-- 文章正文 Start-->.*<!-- 文章正文 End-->";
ereg($text_str,$main_str,$regs);
$main_str = str_replace($regs[0],"<!-- 文章正文 Start-->".$article."<!-- 文章正文 End-->",$main_str);

if (!@dir("../knowledge/".$date)){
mkdir("../knowledge/".$date);
}

if($img_name!=''){
$main_str = str_replace("{)&#!}","<img src ='".$img_name."' align=right hspace=10 vspace=10 style=\"border: 1 solid #000000;\"",$main_str);
}else{
$main_str = str_replace("{)&#!}","",$main_str);
}
$fp=fopen($target_page,"w+");
fwrite($fp,$main_str);
fclose($fp);
@exec("chmod 757 ".$target_page);

if($t){
print "<script language=javascript>alert('装饰知识提交成功!');window.location='knowledge.php';</script>";
}
}

limenghao2 2002-07-07
  • 打赏
  • 举报
回复
update_page函数:
function update_page($path,$kind,$sql,$num,$link)
{
global $DB;
$fn=$path;
$fp=fopen($fn,"r");
$main_str=fread($fp,filesize($fn));
fclose($fp);
$block_str="<!-- ".$kind." Start-->.*<!-- ".$kind." End-->";
ereg($block_str,$main_str,$regs);
$DB ->query($sql);
$news_str="";
$rpos=0;
while(($DB->next_record())&&($rpos<$num))
{
if (empty($link)or($link=='')){
$url=$DB -> f("link_id");
}else{
$url=$link."/".$DB->f("link_id");
}
$news_str.="<img src=\"images/mid_logo1.jpg\" width=\"8\" height=\"7\"> <a href='".$url."' target=_blank class=grayl>".$DB->f("title")."</a>  <br>\n";
$rpos++;
}
$main_str=str_replace($regs[0],"<!-- ".$kind." Start-->".$news_str."<!-- ".$kind." End-->",$main_str);
$fp=fopen($fn,"w");
fwrite($fp,$main_str);
fclose($fp);
}
Arbow 2002-07-07
  • 打赏
  • 举报
回复
后面的那段代码不太懂,以后请教一下……

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧