Re: fgetcsv() delimiters ?
| From: | Burhan Khalid | Date: | Tue, 08 Apr 2003 14:55:38 +0000 |
| Subject: | Re: fgetcsv() delimiters ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142874@lists.php.net to get a copy of this message | ||
On Tue, 2003-04-08 at 08:03, Chris Blake wrote:
> Greetings learned PHP(eople)
>
> The following code opens a text file and puts all the lines in the file
> into an array, so that I can take each line and compile a nice table
> with the order info in it.
>
[ snip ]
> The problem is, I`m using the tab delimiter with fgetcsv(), but some of
> the entries in the file were not entered using this format. Looking at
> the text file content in vim it appears that a single space is used, or
> some other delimiter.
>
> Do I need to loop through the file again using fgetcsv(), this time
> using another delimiter value ?
That sounds like a round-about way of doing it.
If all you want is a list of values in an array, you can use the file()
function, which does exactly that :
$contents = file($filename);
while(list($number,$line) = each($contents)) {
echo "Line Number : ".$number." Contents : ".$line. "<br />";
}
Then, you can use the explode function to lob each "delimited" part off
with whatever delimiter you have. Seems to me calling fgetcsv() would
lead to unnecessary overhead.
My $0.02
--
Burhan Khalid
phplist[at]meidomus[dot]com
Please add a reply-to: header with the
address of the list so replies will
be relayed back to the list.