Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    write to text file help

    if i have
    <?php
    $person = "Bob";
    $var = "doodah";
    $file = "file.txt";
    ?>

    how can i write the variables ($person and $var)to a text file which is defined by a variable ($file)itself.


    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try:

    PHP Code:
    <?php

    $person 
    "Bob";
    $var "doodah";
    $file "file.txt";

    $fp fopen($file,'a+');
    /* the "a+" is for opening the file in read-write mode and appending to its contents */

    fwrite($fp$person);
    fwrite($fp$var);

    ?>
    oughta work i guess.
    'If you don't stand for something, you'll fall for anything.'

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't think its your code but i get
    Parse error: parse error in c:\phpdev\www\text write\doit.php on line 5

    and yes my php stuff does work as i can do the hello world test.

    any ideas?

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm..
    maybe u made a little mistake in copying?
    coz i tried it and it's okay.

    copy and paste what code u've got.

    ps. btw i forgot to close the filestream(?) at the end:
    PHP Code:
    fclose($fp); 
    'If you don't stand for something, you'll fall for anything.'

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if u simply copied and pasted my code then u might have accidentally made some mistake in these two lines:

    $person = "Bob";
    $var = "doodah";
    'If you don't stand for something, you'll fall for anything.'

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i will fiddle and faf tomorrow as its late now.

    thanks so far

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished


  •  

    Posting Permissions

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