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 2 of 2

Thread: using fwrite

  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using fwrite

    Hi

    I have a file (test.txt) containing these lines

    domain.com
    domain2.com
    domain3.com
    ...
    domain100.com


    I need to add domain101.com contained in $new_domain at the end of file

    so I can have
    domain.com
    domain2.com
    domain3.com
    ...
    domain100.com
    domain101.com

    I am trying this

    Code:
    $file = "/usr/local/test.txt";
    if (!file_exists("/usr/local/test.txt")) touch("/usr/local/test.txt");
    $fh = fopen("/usr/local/test.txt", "r");
    $fcontent = fread($fh, filesize("/usr/local/test.txt"));
    
    $towrite = "$new_domain $fcontent";
    
    $fh22 = fopen('/usr/local/test.txt', 'w+');
    fwrite($fh2, $towrite);
    fclose($fh);
    fclose($fh2);

    it doesn't work , it only create a blank file .

    Is there a better way ?

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    $fh22

    $fh2

    You're using incorrect variable names.


  •  

    Posting Permissions

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