Re: Converting tab delimited file to CSV

From: Date: Mon, 18 Feb 2008 16:48:10 +0000
Subject: Re: Converting tab delimited file to CSV
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-269488@lists.php.net to get a copy of this message
On Mon, February 18, 2008 7:11 am, Graham Cossey wrote: > I was wondering if someone could offer some advice please. > > I'm being sent data in tab delimited files which I'm trying to split > into smaller files and convert to comma delimited using PHP. > > Now, I can replace the tabs with commas and opening the resulting > files in a basic text editor all looks fine. However when I open the > files in M$ Excel they're still being treated as tab delimited and all > values are being shoved into a single column. > > What can I do in the PHP code to specifically make the file CSV and be > treated as such by M$ Excel? > > I'm currently just using fopen for old and new files and fwrite. First, note that MS Excel is quite happy to import tab-delimited if you punch the right radio buttons on the import dialog... Next, use fgetcsv and fputcsv with different args ("\t" and ",") to read/write the files, and you should get valid CSV files. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So?

« previous php.general (#269488) next »