-
Writing to a file?
I know how to write to a file, but I want to know if its possible to write to a certain part of the file? The code I use to write text to a file:
PHP Code:
$support="Name: " . $name . "\nMessage: " . $msg . "\nEmail: " . $email . "\nDate: " . $Date;
$fp=fopen("support.php", "a+");
fwrite($fp, $support);
fclose($fp);
How would I make that write after and before some code? So the code looks like this:-
Code:
<HTML><TITLE>Support</TITLE>
<br/><br/>
Name: my name
Message: my message
Email: myemail
Date: 06 August 2007
</HTML>
-
Re: Writing to a file?
you want to append the text then:
PHP Code:
fopen($filename, 'a')
-
Re: Writing to a file?
I already do that, but I want it to write to a certain part of the file (before </html>)
-
Re: Writing to a file?
try reading the contents of the folder to a string, then ad the info to the begining of the string. And add it to the file.
PHP Code:
$fp = foppen("file", "a+");
$content = fread($fp);
$string = "Add this to begining";
$content = $string . $content;
$write = fwrite($fp, $content);
fclose($fp);
-
Re: Writing to a file?
If I did that it'll repeat the code in the file.
-
Re: Writing to a file?
show me what you want to add to the beginning of the file
-
Re: Writing to a file?
Code:
<HTML><TITLE>Support</TITLE>
<br/><br/>
Then the message and after the message:-