ok i have a few questions, first when i uploaded my first .php file to my server it just displayed all the code and did not work. so i searched google for my problem and a guy said to save my file as a .php3 this worked but i am wondering if there is any other way to fix it. and if someone could tell me the difference between a .php and a .php3 file.

my next problem is writing multiple ip addresses to a text file but seperating them on different lines.

i tried using \n and \r but they did not work, they put a space between the ip addresses like this

315.59.135.5 521.21.486.8

i want them like this

315.59.135.5
521.21.486.8

any help would be greatly appriciated

thanks
-Madmee

    This example below is taken from fwrite manual.

    See also
    http://php.net/fopen
    http://php.net/fwrite
    http://php.net/fread

    you can open file for 'a' = append,
    and it will add new lines WITHOUT overwriting already existing lines
    for each fwrite operation, a new line is added

    <?php
    
    $filename = 'test.txt';
    $line1 = "Add this line1 to the file\n";
    $line2 = "Add this line2 to the file\n";
    
    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {
    
       // In our example we're opening $filename in append mode.
       // The file pointer is at the bottom of the file hence 
       // that's where $somecontent will go when we fwrite() it.
       if (!$fp = fopen($filename, 'a')) {
             echo "Cannot open file ($filename)";
             exit;
       }
    
       // Write $somecontent to our opened file.
       if (fwrite($fp, $line1) === FALSE) {
           echo "Cannot write to file ($filename)";
           exit;
       }
       if (fwrite($fp, $line2) === FALSE) {
           echo "Cannot write to file ($filename)";
           exit;
       }
    
       echo "Success, wrote ( $line1 and $line2 ) to file ($filename)";
    
       fclose($fp);
    
    } else {
       echo "The file $filename is not writable";
    }
    
    ?>

    Of course you could make $data = $line1.$line2;
    and do only one fwrite operation

    $data = $line1.$line2;
    $fp = fopen($filename, 'a');
    fwrite($fp, $data);
    fclose($fp);
    echo "Okay $data was written to file.";

      Thanks for your help, I found what i needed. I was using the fread function to see of it worked instead of loading the .txt file, so it was writing correctly the whole time. lol. :p

        good.
        you can mark this solved now, I think

          Write a Reply...