www.webdeveloper.com
Results 1 to 3 of 3

Thread: Three PHP questions

  1. #1
    Join Date
    Sep 2013
    Posts
    12

    Three PHP questions

    PHP Code:
    <?php

        
    // Open the text file
        
    $f fopen("textfile.txt""w");

        
    // Write text
        
    fwrite($f$_POST["name"]); 
        
    //space
        
    fwrite($f$_POST["email"]);

        
    // Close the text file
        
    fclose($f);

        
    // Open file for reading, and read the line
        
    $f fopen("textfile.txt""r");

        
    // Read text
        
    echo fgets($f); 
        
    fclose($f);

        
    ?>
    Hi I have two problems:

    1) How can you close the php file and open another separate URL link after ?

    2) Have it so that that it doesn't replace the previous text on the text file it just writes another bellow?

    3) How do I get a space between the two "Write text's" look for:
    PHP Code:
    //space 
    ?

  2. #2
    Join Date
    Apr 2012
    Posts
    38
    Your questions aren't very clear.

    1) You already closed the php file by fclose($f); didn't you?
    2) Change "w" in "a+" (source: http://www.webdeveloper.com/forum/sh...write-function)
    3) I really don't understand what you mean by this. It could be useful to give us a (better) example.

  3. #3
    Join Date
    May 2003
    Posts
    599
    It's not very clear but I think this is closer to what you are looking for

    PHP Code:
    $line $_POST["name"] . ' ' $_POST["email"] . "\n";
    file_put_contents("textfile.txt",$line,FILE_APPEND); 
    We do precision guesswork

Thread Information

Users Browsing this Thread

There are currently 4 users browsing this thread. (0 members and 4 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles