Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'd like to bring in a csv file and parse it into an array. That I can do, but I'd like to call the array the same as thing as the file using the variable ($file in this case) that I am using to store the file name so that I don't actually have to know the file name (other than when I assigned to $file).Code: Select all
$current_row = 1;
$file = 'temp';
$handle = fopen($file, 'r');
while ( ($data = fgetcsv($handle, 10000, ',') ) !== FALSE )
{
$number_of_fields = count($data);
if ($current_row == 1)
{
//Header line
for ($c=0; $c < $number_of_fields; $c++)
{
$header_array[$c] = $data[$c];
}
}
else
{
//Data line
for ($c=0; $c < $number_of_fields; $c++)
{
$reg[$header_array[$c]][$current_row-2] = $data[$c];
}
}
$current_row++;
}
echo "<PRE>";
print_r ($reg);
echo "</PRE>";If that's possible can I then do the print_r statement again using the $file somehow and not knowing the file name at that point in time?
Thanks
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]