ignoring commas in individual fields when parsing CSV file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

ignoring commas in individual fields when parsing CSV file

Post by clem_c_rock »

Hello,

I'm trying to develop a bullet proof CSV function that can ignore commas that are found in individual field data when parsing through a regular CSV file.

Here's some of the code I'm trying right now:

Code: Select all

$file = fopen( $file_name, "r" );
$cnt = 0;

while( !feof( $file ))
{   
          $line = fgetcsv( $file, 4096 );
          $count = count( $line );

          if( is_array( $line ) && $count > 0 )
          {
                 for( $i = 0; $i < $count ; $i++ )
                 {
                          echo "<br>$line[$i]  ";
                 }
        }
}
          
 fclose( $file );
Any help you can give would be awesome.

Thanks,
Clem
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP Coding question != General Discussion. :?
Locked