PHP - Remove last character of file

前端 未结 1 1006
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 12:21

I have a little php script that removes the last character of a file.

$contents = file_get_contents($path);
rtrim($contents);
$contents = substr($contents, 0         


        
相关标签:
1条回答
  • 2021-01-11 13:21

    Try this

    $fh = fopen($path, 'r+') or die("can't open file");
    
    $stat = fstat($fh);
    ftruncate($fh, $stat['size']-1);
    fclose($fh); 
    

    For more help see this

    0 讨论(0)
提交回复
热议问题