SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    writing to a file

    hey guys...

    I'd like to have a TXT file, and have the user key in stuff in a HTML text box.. where the text gets stored in the TXT file, to be retrieved by other programs later.

    How do I do that? Any ideas?

  2. #2
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,
    The good thing about PHP is that this can be done relatively easily. You need to open the file, insert the data and close the file, simple as that really.

    It can be done like this..

    PHP Code:
    $fp fopen ("/your/filename/here.txt""w"); 
    *** Opens the file for writing
    PHP Code:
    $fp .= $htmlformdata
    *** Appends the HTML Form data to the file.
    PHP Code:
    fclose ($fp); 
    *** Closes the file.

    I'm pretty sure that this is how it's done. If I'm wrong, shoot me!

    Hope this helps,

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi KMxRetro,

    Thanks for the assist... a question on $fp .= $htmlformdata;

    Could you provide me with more info / examples on that command? Or maybe a URL reference.....

    Thanks!

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $fp*.=*$htmlformdata
    I have never seen anything like the above. It implies that PHP is using operator overloading. The only langauage that I have seen that impliments operator overloading is C++. Curious.

    Another example would be
    PHP Code:
    $fp*=*fopen*("/your/filename/here.txt",*"w");
    fwrite($fp$htmlformdata);
    fclose($fp); 
    Also the flag "w" will open the file, truncate it and set the file pointer to the begining of the file overwriting its contents. If you wanted to append onto the end of an existing file you would open the file with the "a" flag.

    You should read the relevent chapter of the manual on this. It is very straightforward.



Bookmarks

Posting Permissions

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