Jump to content

Remove of two header lines?? Code and data pasted


jschofield

Recommended Posts

What I am trying to do here is remove two lines at the top of a text file using a script. Below is my script. I was trying to say in the script is that if it is not numeric then continue which would remove the lines. I am doing something wrong cause I can't get it to work. The included script is for logging only. Any help would be greatly appricated and would say my butt too. Thanks fellow phpers!!

 

Script:

<?php

 

$inputfile = "C:/SMDIM/Data/HSattendance.txt";

$outputfile = "C:/SMDIM/Data/PlainviewHS_Attendance_Data.csv";

$logfilename = "C:/SMDIM/Logs/LPlainviewHS_Attendance_Log.txt";

 

//include log script

include'C:/SMDIM/Translators/importlibrary.inc.php';

 

 

$count = 0;

 

//open the file

if(!$outfilefp = fopen($outputfile, "w")) {

wlogdie("Failed to open $outputfile");

}else{

wlog("Opened $outputfile for writing");

}

//read file

if(!$inputfp = fopen($inputfile, "r")) {

wlogdie("Failed to open $inputfile");

}else{

wlog("Opened $inputfile for reading");

}

 

//remove header lines

while ($row = fgetcsv($inputfp, 1000, ",")){

if($row == "0 > 0"){ continue;}

{

$count++;

writeLine($outfilefp, $row);

}

if($count !== '0') {

wlog("finished the import with a total of $count records");

}else{

wlog("Failed to import data");

}

}

?>

 

TEXT FILE:

 

number_of_records=97

last24hours

20380,3/7/2007,E

20302,3/7/2007,D

20743,3/7/2007,E

20380,3/5/2007,E

20380,3/7/2007,E

20302,3/7/2007,D

20375,3/7/2007,E

20375,3/7/2007,E

20385,3/7/2007,D

20380,3/7/2007,E

 

 

You can use:

 

//This will read all the lines in an array with each line being an element of the array
$lines = file('C:/SMDIM/Data/HSattendance.txt');


foreach ($lines as $line_num => $line) {
   //here you can apply your logic
   //may be the following
  if(is_numeric($line) $to_write .= $line;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.