0

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);  
     } 
 ?>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by hielo
0

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);  
} 
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.