P
P
PO6OT2015-11-25 17:34:58
PHP
PO6OT, 2015-11-25 17:34:58

How to remove the last character from a file?

The file is large, so this method (line operations) will not work:

$f=fopen($file, 'r');
$fcontent=fread($f); //нельзя загружать файл в память - он может не влезть или скрипт будет медленно работать
fclose($f);
$f=fopen($file, 'w');
fwrite($f, substr($fcontent, 0, -1));
fclose($f);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romy4, 2015-11-25
@woonem

find out the file size and here is php.net/manual/ru/function.ftruncate.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question