set fso=server.createobject("scripting.filesystemobject")
set txt=fso.opentext (your_TXT,只读)for i=1 to WHICH_LINE
if numberstr="" then
else
thefirsttxt=numberstr+chr(13) & chr(10)
end if
numberstr=txt.readline
next
c=cint(numberstr)
numbestr=cstr(c+1)
thefirsttxt=numberstr+chr(13) & chr(10)
while not txt.endofstream
thelasttxt=txt.readline()+chr(13)+chr(10)
wend
txt.close
alltxt=thefirsttxt+thelasttxt
set txt=fos.opentext(YOU_TXT,只写)
txt.write alltxt
txt.close
set txt=nothing
set fso=nothing
$month = 2; // 指定月份$filename = "month.txt";
if(!file_exists($filename)) {
$ar = array(0,0,0,0,0,0,0,0,0,0,0,0);
$fp = fopen($filename,"w");
fwrite($fp,join("\n",$ar));
fclose($fp);
}
$fp = fopen($filename,"r+");
$ar = split("\n",fread($fp,filesize($filename)));$ar[$month-1] = 5; // 赋值rewind($fp);
fwrite($fp,join("\n",$ar));
fclose($fp);
?>
谢谢你的代码
不过我还有一个问题
如果我有一个文本文件1.txt
内容为
2002-2-16 21:06
2
----------
第一行是时间信息
第二行是一个数值(计数器)
现在我想将第二行的数值可以动态递增(每刷新一次页面,其值加1),请问如何实现?因为这2行数据之间没有联系,所以好像不能用递归赋值??
比如是第二行,$row = 2;
赋值时 $ar[$row-1]++;
你只要在需要时把那段代码include进来就可以了
$row = 0; //要递增的行,注意行号由0开始 $fp = fopen($file, "r+");
flock($fp, 2);
$str = fread($fp, fileSize($file));
$data = explode("\n", $str); $data[$row] = trim($data[$row]);
$data[$row]++; //递增 rewind($fp);
fwrite($fp, implode("\n", $data));
fclose($fp);?>