Jump to content

dan245

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dan245's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=coldkill link=topic=111486.msg451870#msg451870 date=1160839615] 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]
  2. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.