2 回答
TA贡献1898条经验 获得超8个赞
您不必在文件中保存实际前缀 (202000)。只需保存计数器(1、2、3、4、5 等)
<?php
$file = 'counter.txt';
$prefix = '202000';
//If file exists then grab content of file(nr) and add it with one else set counter=1
file_exists($file) ? $counter = file_get_contents($file)+1 : $counter = 1;
//This is the number you would like to use (2020001, 2020002 ... 20200010 etc)
$use_number = $prefix . $counter;
//Save counter value to file (1,2,3,4 etc...)
file_put_contents($file, $counter);
?>
TA贡献1821条经验 获得超4个赞
您可以计算所有文件行,将它们用作计数器的基数
$file = 'someFiel.txt';
$counter = 0; // the file lines
$handle = fopen($file, "r");
while(!feof($handle)){
$line = fgets($handle);
$counter++;
}
fclose($handle); //close the file reader
$next_line_no = $counter + 1; // this will add 1 to your counter
然后只需添加您的前缀和下一行
$next_line = '202000' . $next_line_no;
您可以通过计算行数来对 MySQL 执行相同的操作,然后使用 counter + 1 再次添加前缀;
- 2 回答
- 0 关注
- 100 浏览
添加回答
举报