Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2006, 11:37 PM
Authorized User
 
Join Date: May 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default ignoring commas in individual fields when parsing


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:



$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

 
Old April 20th, 2006, 04:14 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"I'm trying to develop a bullet proof CSV function that can ignore commas"

The comma-separated values (CSV) file format is a tabular data format that has fields separated by the comma character and quoted by the double quote character.

I've only seen CSV (I didn't know there was a name for it to be honnest) on excel document and some crap database -> text file.

So far I got: You are trying to create a system which will open a CSV?? but ignore the commas?

do you mean remove the commas from the file / string?
if thats the case check out: str_replace , replace "," by "" and job done..





Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting the continuous commas mrame XSLT 2 July 23rd, 2008 12:46 PM
remove commas and space in a string kumiko Classic ASP Basics 1 January 10th, 2008 11:42 PM
XSLT issue to add commas to values 2BOrNot2B XSLT 3 October 31st, 2006 12:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.