Home  >  Article  >  Backend Development  >  请问一个文本存放的有关问题,没搞明白如何整

请问一个文本存放的有关问题,没搞明白如何整

WBOY
WBOYOriginal
2016-06-13 13:43:53726browse

请教一个文本存放的问题,没搞明白怎么整
接收到一个变量要将它写进文本,变量$text,此接受程序是一进程,变量是追加进文本的;
比如存放到1.txt中,在存放前判断1.txt大小有没有100K,没有的话将变量写进文本,当1.txt大于100K的时候,写进另一文本,然后再将变量存放到这个文本中去,这个文本又满了后写进写一文本,如此推进。



------解决方案--------------------
用一个文件,如 0.txt ,记录最后保存数据的文件名序号,如内容是1,
在写文件前,判断 1.txt 的大小,如果 如果 > 100K,则 0.txt 的内容变为 2, 并新建 2.txt 写入。
------解决方案--------------------
function writeIn()
{
static $i = 1;
$fh = fopen($i. '.txt ', 'a+ ');
if(filesize($i. '.txt ') > = 3)
{
$i += 1;
writeIn();
}
fwrite($fh, '123 ');
fclose($fh);
}
writeIn();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn