2 回答

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊
您不必在文件中保存實(shí)際前綴 (202000)。只需保存計(jì)數(shù)器(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貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊
您可以計(jì)算所有文件行,將它們用作計(jì)數(shù)器的基數(shù)
$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;
您可以通過(guò)計(jì)算行數(shù)來(lái)對(duì) MySQL 執(zhí)行相同的操作,然后使用 counter + 1 再次添加前綴;
- 2 回答
- 0 關(guān)注
- 125 瀏覽
添加回答
舉報(bào)