I am getting this as my output from the code below and i need to get just the first and last column. This is my first time useing fgetcsv so any help would be great.

Array ( [0] => 1~Joe~Salem~VA~Captain ) Array ( [0] => 2~Sara~Vinton~VA~Lieutenant ) Array ( [0] => 3~Dave~Salem~VA~Captain ) Array ( [0] => 4~Fred~Salem~VA~Major ) Array ( [0] => 5~Diana~Vinton~VA~Captain ) Array ( [0] => 6~Brian~Roanoke~VA~Major )

<?php 
        $namefile = 'pilots.txt';  
        $OUTFILE = fopen($namefile, 'r') or die("Can't open $namefile for read");  
        $name = fgets($OUTFILE,4096);  

             if($OUTFILE){            
        while (!feof($OUTFILE))   
         {   
               print_r(fgetcsv($OUTFILE));                 
        //    $name = fgets($OUTFILE, 4096); 
        //    echo("<br />$name");             
          //  print ("<br />$name");  
           // $name = fgets($OUTFILE,4000);  
       }  
        fclose ($OUTFILE);  
     } 
 ?>

you need to add '~' as the third argument to fgetcsv():

<?php 
$namefile = 'pilots.txt';  
$OUTFILE = fopen($namefile, 'r') or die("Can't open $namefile for read");  
$name = fgets($OUTFILE,4096);  
if($OUTFILE)
{
	while (!feof($OUTFILE))
	{
		$row=fgetcsv($OUTFILE,1024,'~');
		echo sprintf('%s %s', $row[0], $row[4]); 
	}
	fclose ($OUTFILE);  
} 
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.