Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Amending a file

Status
Not open for further replies.

jayne1

Technical User
Feb 5, 2002
7
GB
hi guys,

I'm trying to amend a text file so that the new text is placed at the beginning of the file without losing the original text.

I thought i had figured it out using a combination of "aw" modes with fopen .....but this only writes to end of the file!

PLEASE HELP!
 
you cannot directly add text in the beggining. The easiest solution to do what you want is:

$newtext="blabla";
$newtext.=implode("",file("filename.txt")); // this way you add the new text to the begining of the file

$fp=fopen("filename.txt","w+"); // recreate the file.
fwrite($fp,$newtext,sizeof($newtext)); // write the new text and the old one
fclose($fp);

Attencion, i do not know the params order of the function fwrite.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top