Creating a batch file from a CSV file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Creating a batch file from a CSV file

Post by Linkjames »

Hi guys

I work in testing and I have a CSV file containing all the tests I use (Several thousand). Amongst other things, the tests have a status and I need to extract the tests out, edit them with some find/replace work and put it all back together into a batch file to run the ones that are not yet run.

Anyway, I have got as far as

Code: Select all

<?PHP
$filename = 'E:\Testing\testresults\dnt3.csv';
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);
echo $contents;
?>
which opens the csv file into internet explorer, but it is totally un formatted. It is not even seperated by line (Which I thought happened automatically)

Anyone point me in the direction of a function I could make use of to split it into lines?
Cheers guys - LinkJames
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

update - although not fixed, I realise what an idiot I am. I am, of course, outputing an identical file, hence why its coming out unformatted, there are no HTML tags (slap)
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

I am making progress :)

I am trying to find a function that will find lines containg a certain string and either delete the rest of the lines.

Cheers again - LinkJames
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Still going ;)

I have removed all the lines I dont want, which leaves me with several lines which look like this

Code: Select all

I2,IDXF8G7 ,N037581A,undef OS,To be run ,T3 ,XFH , , I2,IDXF8G7 ,N038572A,undef OS,To be run ,T3 ,XFH , ,
which I need to turn into

Code: Select all

call trun INTERNL2 IDXF8G7 -s N037581A
which basically means doing the following:
Add "call trun" at the start of each line
Replace I2 with INTERNL2
Place "-s" between the group and sweet (IDXF8G7 and N037581A in this case)
Deleteing the rest of the line
and keep doing it for each line

So far I have

Code: Select all

<?PHP
$filename = 'E:\Testing\testresults\dnt3.csv';
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
$delimiter = "\n";
$splitcontents = explode($delimiter, $contents); 
$counter="1";
foreach ( $splitcontents as $color )
{
$counter = $counter+1;
if (strpos($color, "To be run")) {
   echo $color;   
} else {
}
}
fclose($fp);
?>
Any help appreciated - LinkJames
Post Reply