Stack Exchange
How to remove the last line of CSV file
<?php


                $row = 0;
                $handle = fopen("data20150804.log", "r");
                while (!feof($handle) ) {

                    $line_of_text = fgetcsv($handle, 1024, ",");
                    $num = count($line_of_text);
                    $timeStamp = $line_of_text[0];
                    $visibility = $line_of_text[1]; 
                    $pressure = $line_of_text[2];
                    $rain = $line_of_text[3];
                    $temperature = $line_of_text[4];    
                    $humidity = $line_of_text[5];
                    $dewpoint = $line_of_text[6];
                    $R1windSpeed = $line_of_text[7];    
                    $R1wSpeed3s = $line_of_text[8];
                    $R1wSpeed2min = $line_of_text[9];   
                    $R1wSpeed10min = $line_of_text[10];
                    $R1windDirDeg = $line_of_text[11];
                    $R1wDirDeg3s = $line_of_text[12];   
                    $R1wDirDeg2min = $line_of_text[13];
                    $R1wDirDeg10min = $line_of_text[14];
                    $R2windSpeed = $line_of_text[15];   
                    $R2wSpeed3s = $line_of_text[16];
                    $R2wSpeed2min = $line_of_text[17];  
                    $R2wSpeed10min = $line_of_text[18];
                    $R2windDirDeg = $line_of_text[19];
                    $R2wDirDeg3s = $line_of_text[20];   
                    $R2wDirDeg2min = $line_of_text[21];
                    $R2wDirDeg10min = $line_of_text[22];                        
                    $gust = $line_of_text[23];  


                    //$row++;
                }

                fclose($handle);
   ?>

my csv file is keeping generate the data in a few second.
I want to remove the last row of the csv because my system is reading the last row data and my last row is blank.

If you use the SPLFileObject csv reader you can tell it to ignore blank lines

@MarkBaker can show me example...sry I am new ...

If you check the documentation for fgetcsv you'll see the note about blank line returns. So if you do a check after:
$line_of_text = fgetcsv($handle, 1024, ",");

Along the lines of:
if (count($line_of_text) == 0 || $line_of_text[0] === null) {
    continue;
}

This should do what you need.

its possible to make it read the previous row? because the last row is blank ...:(

You will have already read the last line of text with the while loop you have previous. Are you only reading a 1 line CSV? Or are you trying to read the last full line of the CSV? If it's the latter then my solution above should still work for you.

Try this one
<?php
$row = 0;
$file = new SplFileObject("data20150804.log.csv");

$file->setFlags(SplFileObject::READ_CSV);
$file->setFlags(SplFileObject::SKIP_EMPTY);
foreach ($file as $line_of_text) {
    $num = count($line_of_text);
                    $timeStamp = $line_of_text[0];
                    $visibility = $line_of_text[1]; 
                    $pressure = $line_of_text[2];
                    $rain = $line_of_text[3];
                    $temperature = $line_of_text[4];    
                    $humidity = $line_of_text[5];
                    $dewpoint = $line_of_text[6];
                    $R1windSpeed = $line_of_text[7];    
                    $R1wSpeed3s = $line_of_text[8];
                    $R1wSpeed2min = $line_of_text[9];   
                    $R1wSpeed10min = $line_of_text[10];
                    $R1windDirDeg = $line_of_text[11];
                    $R1wDirDeg3s = $line_of_text[12];   
                    $R1wDirDeg2min = $line_of_text[13];
                    $R1wDirDeg10min = $line_of_text[14];
                    $R2windSpeed = $line_of_text[15];   
                    $R2wSpeed3s = $line_of_text[16];
                    $R2wSpeed2min = $line_of_text[17];  
                    $R2wSpeed10min = $line_of_text[18];
                    $R2windDirDeg = $line_of_text[19];
                    $R2wDirDeg3s = $line_of_text[20];   
                    $R2wDirDeg2min = $line_of_text[21];
                    $R2wDirDeg10min = $line_of_text[22];                        
                    $gust = $line_of_text[23];
}
?>

I hope it will help full for you.

its doesn;t work... :(
because my system is reading the last row and the last row is blank...
its possible to make it read previous row? I mean -1 rows

$file->setFlags(SplFileObject::SKIP_EMPTY);
