Hi,
I use since a good time now a good little script to read a CSV file (\";\" separated).
The script is this one (I found it somewhere over the Internet)
########
<?php function splice($filename){
if(file_exists($filename)){
global $value; $value=array(\"0\"); // clear the array.
$rows=file($filename); // break text file into a rows array
for($num=0;$num < count($rows); ++$num){ $column=split(\";\",$rows[$num]);
$value[$num]=$column;}}} ?>
########
You call that function with a line like that :
########
splice(\"dir/data.csv\");
$txt = $value[10][3];
echo $txt;
########
It will print the data in the 11th line (the first line is \"0\") and the 4th column.
This is simple, and doesn\'t need any MySQL or special hosting, etc.
But it seems to be very CPU using in my case (for exemple, I\'ve got one \".php3\" file that read in 2 different CSV files of 400 ko each)
Is it normal ?
Is it better to use \"fopen\", or \"fread\", \"fgetscv\" or anything else than \"file\" ?
Have you got a faster function ?
Moreover, in my case, i don\'t need all the lines in the \"database.csv\". before I open it, I know precisely what line I must work with. Is it possible to open the csv by using only the line I want to work with ? Or maybe to open the file and put in an array only the line I need instead of the complete file ?
Thanks for your help
Steph.
I use since a good time now a good little script to read a CSV file (\";\" separated).
The script is this one (I found it somewhere over the Internet)
########
<?php function splice($filename){
if(file_exists($filename)){
global $value; $value=array(\"0\"); // clear the array.
$rows=file($filename); // break text file into a rows array
for($num=0;$num < count($rows); ++$num){ $column=split(\";\",$rows[$num]);
$value[$num]=$column;}}} ?>
########
You call that function with a line like that :
########
splice(\"dir/data.csv\");
$txt = $value[10][3];
echo $txt;
########
It will print the data in the 11th line (the first line is \"0\") and the 4th column.
This is simple, and doesn\'t need any MySQL or special hosting, etc.
But it seems to be very CPU using in my case (for exemple, I\'ve got one \".php3\" file that read in 2 different CSV files of 400 ko each)
Is it normal ?
Is it better to use \"fopen\", or \"fread\", \"fgetscv\" or anything else than \"file\" ?
Have you got a faster function ?
Moreover, in my case, i don\'t need all the lines in the \"database.csv\". before I open it, I know precisely what line I must work with. Is it possible to open the csv by using only the line I want to work with ? Or maybe to open the file and put in an array only the line I need instead of the complete file ?
Thanks for your help
Steph.