Re: Parse Question Using list()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> $line = fgets($handle);
>
> list($col1, $col2, $col3) = $line;
[8<]
> echo "c1 is $col1 and c2 is $col2 and c3 is $col3".'<br>'; // this shows
> just 1st char of each field

That's odd, I would have expected $col1, $col2, and $col3 to be NULL.
That's what I get when I try to assign a string to list(). It expects
a PHP array.

You could tackle this in a couple of different ways. Either split your
string into an array first:

$line = fgets($handle);
$columns = explode(",", trim($line));
list($col1,$col2,$col3) = $columns;

Or look at using fgetcsv(), which will save you a step or two:

http://php.net/manual/en/function.fgetcsv.php

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux