PHP Increment a counting variable in a text file

前端 未结 5 1917
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条回答
  •  Happy的楠姐
    2020-12-10 21:01

    This works for me though

    $count = intval(file_get_contents('count.txt'));
    file_put_contents('count.txt', ++$count);
    echo file_get_contents('count.txt');
    

提交回复
热议问题