« 网页字体大小代码清理了一下友情链接 »

用Stream生成html (utf-8文件)

模板文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>$laos_title$ - www.dxpai.com</title>
</head>
<body>
<div id="guides">
    <div class="left">当前位置:$laos_guide$</div>
</div>
<div id="main1">
    <div class="left">
     <div class="tit">$laos_tit$</div>
  <ul>
  $laos_list$
  </ul>
</div>
<div class="right">
  <h3 class="line">热点文章</h3>
  <ul>
   $laos_hot$  
  </ul>
</div>
</div>
</body>
</html>


生成文件:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>laos_生成html - www.dxpai.com</title>
</head>

<body>
<% 
function readfile(l1)
dim stm,l2
l2=server.mappath(l1)
set stm=server.createobject("ADODB.Stream")
stm.charset="utf-8"
stm.open
stm.loadfromfile l2
readfile=stm.readtext
set stm=nothing
end function
'用Stream生成utf-8文件
sub create_u(file_name,filetype)
    dim objStream
Set objStream = Server.CreateObject("AD"&"ODB.S"&"tre"&"am")
    With objStream
    .Open
    .Charset = "utf-8"
    .Position = objStream.Size
    .WriteText=filetype
    .SaveToFile server.mappath(file_name),2 
    .Close
    End With
    Set objStream = Nothing
end sub
dim temp1,tempstr
temp=readfile("test.html") '把模板内容赋值给temp变量
'下面开始替换
'替换 $laos_guide$
tempstr="首页 >> 文章列表"
temp = replace(temp,"$laos_guide$",tempstr)
'替换$laos_title$
tempstr="upasp"
temp = replace(temp,"$laos_title$",tempstr)
'替换$laos_tit$
tempstr="文章列表"
temp = replace(temp,"$laos_tit$",tempstr)
'替换 $laos_list$
tempstr="<li>哈哈笑</li>"
temp = replace(temp,"$laos_list$",tempstr) 
'替换$laos_hot$
tempstr="<li>中国人</li>"
temp = replace(temp,"$laos_hot$",tempstr)
'好了,模板里的都替换完了,下面开始生成html文件
'注意,下面生成的文件是是根目录的news文件夹内,如果没有,请先建立这个文件夹
call create_u("index.html",temp) 
%>
</body>
</html>

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Copyright www.0097.org Some Rights Reserved.