Jump to content
php.lv forumi

fwrite izdzēst tekstu


stencilz

Recommended Posts

$file = "max.txt";
$open = fopen($file, "r+");
$max = fread($open, filesize($file));
if($count > $max)
 {
fwrite($open, $count);
 }
fclose($open);

 

gribu ierakstīt maksimālo lietotāju skaitu, bet kā lai nodzēš iepriekšējo skaitu? man saglabā tā 0123...

Link to comment
Share on other sites

$file = "max.txt";
$open = fopen($file, "r+");
$max = fread($open, filesize($file));
if($count > $max)
 {
$open_2 = fopen($file, "w");
fwrite($open_2, $count);
 }
fclose($open);

 

izdarīju šādi :)

Edited by stencilz
Link to comment
Share on other sites

'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

ja nevajag lasīt, tad tikai 'w'

Edited by Val
Link to comment
Share on other sites

Val, pamēģini pats:

$file = "bla.txt";
$open = fopen($file, "w+");
$content = fread($open, filesize($file));
echo $content;

 

w+ iztukšo failu pie atvēršanas. Tākā nolasīt neko nevar (pēc tam, protams, varam nolasīt, bet mums jau vajag tieši oriģinālos datus nolasīt).

Edited by andrisp
Link to comment
Share on other sites

×
×
  • Create New...