🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.php
3 messages
3 total messages Started by VipeR Tue, 04 Sep 2001 13:51
dodawanie linii na poczatku pliku
#2192
Author: VipeR
Date: Tue, 04 Sep 2001 13:51
10 lines
1171 bytes
To pewnie bedzie banalne pytanie dla wtajemniczonych grupowiczow:
fwrite z parametrem "a" dodaje tekst na koncu pliku. Czy jest mozliwosc
dodania jej
na samym poczatku? Jesli nie, czy jest jakis inny sposob na obejscie tego
problemu?
(oprocz kopiowania calej zawartosci pliku i pozniej wklejanie jej?)

pozdr,

VipeR
Re: dodawanie linii na poczatku pliku
#2193
Author: Marcin
Date: Tue, 04 Sep 2001 14:10
31 lines
1902 bytes
> To pewnie bedzie banalne pytanie dla wtajemniczonych grupowiczow:
> fwrite z parametrem "a" dodaje tekst na koncu pliku. Czy jest mozliwosc
> dodania jej
> na samym poczatku?

podaje za php.net

pozdrawiam

Marcin

------------------------------------------------------------------------

Inside the second parameter, the mode, can contain two letters. So if you
were to put an "a" and a "w" there,
ex. $fp = fopen ("text.txt", "aw");

it would behave as follows: When you fputs() something to the text.txt it
will do everything that "a" does, but it will also carry over some
attributes of "w"; In this case it will place the file pointer to the
begining of the file, which I find quite handy.

Here is an example of a little script taking advantage of this:
<?
$fp = fopen ("php.txt", "aw");
$fputs ("$name, $date, $title, $news");
fclose ($fp);
?>

This simply will take variables and write them into the *top* of a text file
without deleting any of the origional text.
Re: dodawanie linii na poczatku pliku
#2194
Author: Grzegorz Skaruz
Date: Tue, 04 Sep 2001 14:50
20 lines
1401 bytes
Pięknego dnia Tue, 4 Sep 2001 15:51:12 +0200 "VipeR" <viper@demo.pl>
napisał:

>To pewnie bedzie banalne pytanie dla wtajemniczonych grupowiczow:
>fwrite z parametrem "a" dodaje tekst na koncu pliku. Czy jest mozliwosc
>dodania jej
>na samym poczatku? Jesli nie, czy jest jakis inny sposob na obejscie tego
>problemu?
>(oprocz kopiowania calej zawartosci pliku i pozniej wklejanie jej?)

$fid=fopen($plik,"r+");
$wpis=$wpis. fread($fid,filesize($plik));      
rewind($fid);
fputs($fid,"$wpis");
fclose($fid);

-- 
Grzegorz Skaruz
grzegorz@skaruz.com
www.skaruz.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads