Parse Question Using list()

From: Date: Thu, 01 Oct 2009 23:32:46 +0000
Subject: Parse Question Using list()
Groups: php.general 
Request: Send a blank email to php-general+get-298452@lists.php.net to get a copy of this message
newbie import csv question file is like: stuff1,stuff2,stuff3 stuff1,stuff2,stuff3 stuff1,stuff2,stuff3 stuff1,stuff2,stuff3 etc. Problem: when I try to parse out the 3 fields and display them using list() it just gets just 1st char of each field ... Q: How do I get it to set $col1 - 2 & $col3 to the full contents of each for each line (not just 1st char)? <?php // on a mac but with windows linefeed returns in file $handle = fopen("file:///path/_impfool/test.csv", "r"); while (!feof ($handle)) { $line = fgets($handle); list($col1, $col2, $col3) = $line; echo $line.''.' line<br>'; // this shows the whole line ok echo "c1 is $col1 and c2 is $col2 and c3 is $col3".'<br>'; // this shows just 1st char of each field } ?> Thanks, cool@hosting4days.com

« previous php.general (#298452) next »