Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete last line and check data in text file
    primarykey
    data
    text
    <p>I have the following code to write data to a text file.</p> <pre><code>$somecontent = "data|data1|data2|data3"; $filename = 'test.txt'; // 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 (!$handle = FOPEN($filename, 'a')) { PRINT "Cannot open file ($filename)"; EXIT; } // Write $somecontent to our opened file. IF (!FWRITE($handle, $somecontent)) { PRINT "Cannot write to file ($filename)"; EXIT; } PRINT "Success, wrote ($somecontent) to file ($filename)"; FCLOSE($handle); } ELSE { PRINT "The file $filename is not writable"; } </code></pre> <p>Now I want this text file to only every have 10 lines of data and when a new line of data is added which is unique to the other lines then the last line of data is deleted and a new line of data is added.</p> <p>From research I have found the following code however total no idea how to implement it on the above code.</p> <p><a href="https://stackoverflow.com/questions/7711829/check-for-duplicate-value-in-text-file-array-with-php">check for duplicate value in text file/array with php</a></p> <p>and also what is the easiest way to implement the following code? </p> <pre><code>&lt;? $inp = file('yourfile.name'); $out = fopen('yourfile.name','w'); for ($I=0;$i&lt;count($inp)-1);$i++) fwrite($out,$inp[$I]); fclose($out)l ?&gt; </code></pre> <p>Thanks for any help from a PHP newbie.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload