On Thu, Mar 15, 2012 at 6:40 PM, Andrew Ballard <aball...@gmail.com> wrote:
> On Thu, Mar 15, 2012 at 1:29 PM, Jay Blanchard
> <jay.blanch...@sigmaphinothing.org> wrote:
>> On 3/15/2012 12:23 PM, Matijn Woudt wrote:
>>>
>>> On Thu, Mar 15, 2012 at 6:09 PM, Jay Blanchard
>>> <jay.blanch...@sigmaphinothing.org>  wrote:
>>>>
>>>> I thought that fgetcsv returned an array. I can work with it like an
>>>> array
>>>> but I get the following warning when using it
>>>>
>>>> |Warning:  implode(): Invalid arguments passed on line 155
>>>>
>>>> 154     $csvCurrentLine = fgetcsv($csvFile, 4096, ',');
>>>> 155     $currentLine = implode(",", $csvCurrentLine);
>>>> |
>>>>
>>>> Everything that I have read online indicates that it is because
>>>> $csvCurrentLine is not declared as an array. Adding a line to the code
>>>>
>>>> 153 |$csvCurrentLine = array();
>>>>
>>>> Does not get rid of the warning. The warning isn't interfering with the
>>>> script working, but it us annoying. Does anyone know the solution?
>>>>
>>>> Thanks!
>>>>
>>>> Jay
>>>> |
>>>
>>> Are you using this in a loop or something? fgetcsv returns FALSE on
>>> errors, including End Of File.
>>>
>>> [/snip]
>>
>> I am using it in a loop. End Of File is an error?
>
> Yes.  "fgetcsv() returns NULL if an invalid handle is supplied or
> FALSE on other errors, including end of file."
>
> I usually use it in a while loop like this:
>
> <?php
>
> while ($row = fgetcsv($csvFilePointer)) {
>    // ... process the row
> }
>
> ?>

Please, don't do that. Use this instead:
while (($csvCurrentLine = fgetcsv($csvFile, 4096, ',')) !== FALSE) {
}

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

Reply via email to