dan245
-
Posts
2 -
Joined
-
Last visited
Never
Posts posted by dan245
-
-
To delete the contents of a text file try:
[code]
<?php
if ( isset ( $_POST['submit'] ) ) {
$file = "whatever.txt";
$fp = fopen( $file, "w" );
if ( fwrite ( $fp, "" ) ) {
print "The file $file has been erased!";
} else {
print "Writing to the file: $file has failed!";
}
}
?>
[/code]
If you would like to overwrite the file, put text in the empty quotes in this line:
[code]
if ( fwrite ( $fp, "This will overwrite the text!" ) ) {
[/code]
Then replace that line with the other line of that code.
As for updating text try doing this:
[code]
<?php
if ( isset ( $_POST['submit'] ) ) {
$file = "whatever.txt";
$fp = fopen( $file, "a" ); // added append which is what "a" means
if ( fwrite ( $fp, "text1<br>text2<br>text3<br>text4<br>text5" ) ) {
print "The file $file has been appended too!";
} else {
print "Writing to the file: $file has failed!";
}
}
?>
[/code]
-Dan M.
is this possible?
in PHP Coding Help
Posted
You can't use fread to execute PHP code since it literally reads a string and doesn't parse the code.
When you include the page the PHP engine parses through the code executing it as it goes along. With the fread function it would just see a massive string with <?php at the beginning but it wouldn't parse it.
[/quote]
Like coldkill said you can't execute a PHP page. You can't even execute a HTML page with fread() [unless opening a URL]. To put it in more simple terms, It can only only read plain text, the source code, and URL's too.
If you want to learn know more look here:
[url=http://www.php.net/manual/en/function.fread.php]http://www.php.net/manual/en/function.fread.php[/url]