Forum Moderators: coopster
also this is quite a small problem i have used th following code:
<?php
$filename = "test.txt";
if ( $a = fopen( $filename, "a")) {
flock( $a, LOCK_SH );
fwrite($a, $message);
flock( $a, LOCK_UN );
} else {
print "file couldn't be opened";
}
fclose( $a );
?>
After $message in the fwrite() function i have tried using <br> tags enclosed in single and double quotes, i have tried using \n\n to make it so that the next entry will be on a new line, i get a parse error, can anyone help with this too?
it is just a first script but i would really like to know how to set a maximum amount of entries to display on the page, without having to store all of the entries in the file like only displaying 10 but having 10000 in the text file, i want to display 10 and only have 10 in the text file.
<?php
$filename = "test.txt";
$contents=file($filename);
array_push($contents,$newEntry);
while (count($contents) > 10) {
array_shift($contents);
}
then do:
if ( $a = fopen( $filename, "a")) {
flock( $a, LOCK_SH );
fwrite($a, $contents);
flock( $a, LOCK_UN );
} else {
print "file couldn't be opened";
}
fclose( $a );
?>
I am not sure about explicity locking the files - I have never had to do this.
You should be able to put <br> in your entries like
$newEntry=preg_replace("/\n/","<br>",$newEntry)
which will
a) replace newlines with <br>
b) mean each entry is on one line which makes it easier to manage the entries
$newEntry=preg_replace("/\n/","<br>",$newEntry)
this might also have something to do with the fact that instead of saving the contents of the form field into the file it is saving the word Array, i have only been doing it a week :s
if filesize($filename) > 512 { delete contents of file }
got to look into it further, can anyone tell me though if 512 would be accepted as 512 kilobits or 512 bytes?
cheers for your help so far peeps