Trey Copeland
Trey Copeland

Reputation: 3527

Convert Comma Delimited To Tab Delimited Using PHP

I'm trying to upload a file to Amazon MWS. I get an inventory file in .csv format like this:

feed.csv

sku,qty
ABC,5
HHA,8

How can I convert this to tab delimited when I read it in like this:

$file = file_get_contents('feed.csv', 'r') or die("cant open file");

echo($file);

Upvotes: 1

Views: 1832

Answers (1)

Rohit
Rohit

Reputation: 3146

If you have no other commas, the easy way is to replace all commas with tabs:

$file = str_replace(',', "\t", $file);

A more complete solution would be to use fgetcsv to read the file, and then create a tab-delimited csv from the read data with fputcsv.

Upvotes: 1

Related Questions