hey anyone wanna help a newbie?
I want to have php write information to a text file. I would like to write to the beginning of a document from a html form. So far Ive only been able to either overerite the document or appened the document. do I need a script that will analysize the size of the information from the form and add that much white space first?
Ive been hacking away and its starting to get ugly over here
could anyone help me with some pointers on completing such a script?
thanks alot, --don .:inept:.
file handling for idiots
Moderator: General Moderators
Code: Select all
$fp = fopen($filename, "r+");
fwrite($fp, $contentToWrite);
fclose($fp);file handling for idiots
the script above is basically what I have right now, It still seems that using the "r+" read/write mode still overwrites whatever is at the beginning of the file. Im trying to set up a script that i can write information from a form into reverse chronological order, so the most recent entrys to the log are at the top.
should the fwrite function using "r+" not overwrite data already in the filehandle??
-don
should the fwrite function using "r+" not overwrite data already in the filehandle??
-don
- James Pelow
- Site Admin
- Posts: 51
- Joined: Sat Jun 01, 2002 5:28 am
- Location: Killiney, Co. Dublin, Ireland
- Contact:
Um..
Would it not just be easier to have it append to the file and organise the output later?
That's just a snip from phpmac.com but you should get the idea.
-James
Code: Select all
if($total <> 0) {
for($sortno = 0; $sortno < $total; $sortno++) {
$line = explode("||", $fileї$sortno]);
if ($lineї3] <> "News:") {
$arrayї] = "$lineї6]||$lineї0]||$lineї1]||$lineї2]||$lineї3]||$lineї4]||$lineї5]||$lineї6]||$lineї7]||$lineї8]||$lineї9]||\n";
}
} // End Loop
rsort($array);
} // End Total Check
for ($pua=0; $max_fp_dis > $pua; $pua++) {
$print_art_split = explode("||", $arrayї$pua]);
$time = (date($date_format, $print_art_splitї0])); // Convert the Unix Time Stamp to a Date (Irish Date Format)
}That's just a snip from phpmac.com but you should get the idea.
-James
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
append text to a file
You should try to open the file like this:
I guess the 'a' is for append.
Good luck

Code: Select all
$fp=fopen("nameOfTheFile", "aw");Good luck