Tab deliminated FPUTCSV() in php

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

Post Reply
varma457
Forum Newbie
Posts: 23
Joined: Sat Jul 11, 2009 2:43 pm

Tab deliminated FPUTCSV() in php

Post by varma457 »

Hi,

I have a problem with tab deliminated fputcsv().

I tried it like..

$list=array("adsha,afjahf,asasdf",);
$file = fopen("contacts.csv","a");
foreach ($list as $line)
{
fputcsv($file, split("\t", $line));
}


But it is not working..
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Tab deliminated FPUTCSV() in php

Post by jackpf »

Where are the tabs? That string looks comma delimited to me....

Also I think split() is deprecated. You should use preg_split() instead.

And how do you mean "not working"?
varma457
Forum Newbie
Posts: 23
Joined: Sat Jul 11, 2009 2:43 pm

Re: Tab deliminated FPUTCSV() in php

Post by varma457 »

jackpf wrote:Where are the tabs? That string looks comma delimited to me....

Also I think split() is deprecated. You should use preg_split() instead.

And how do you mean "not working"?
what should I change for above code ..In order to get tab deliminated output
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Tab deliminated FPUTCSV() in php

Post by jackpf »

Well, if you want each comma delimited word as a formatted csv line, then $list=array("adsha afjahf asasdf") and use preg_split('/\t/', $list);
Post Reply