jschofield Posted March 8, 2007 Share Posted March 8, 2007 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 Link to comment https://forums.phpfreaks.com/topic/41862-remove-of-two-header-lines-code-and-data-pasted/ Share on other sites More sharing options...
skali Posted March 9, 2007 Share Posted March 9, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/41862-remove-of-two-header-lines-code-and-data-pasted/#findComment-203106 Share on other sites More sharing options...
jschofield Posted March 9, 2007 Author Share Posted March 9, 2007 Thanks Skali..ill give her a shot. Link to comment https://forums.phpfreaks.com/topic/41862-remove-of-two-header-lines-code-and-data-pasted/#findComment-203485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.