PHP Increment a counting variable in a text file

前端 未结 5 1909
Happy的楠姐
Happy的楠姐 2020-12-10 20:14

This seems simple but I can\'t figure it out.

file_get_contents(\'count.txt\');
$variable_from_file++;
file_put_contents(\'count.txt\', $variable_from_file);         


        
5条回答
  •  有刺的猬
    2020-12-10 20:54

    $variable_from_file = (int)file_get_contents('count.txt');
    

    But notice that this is not thread-safe.

提交回复
热议问题