/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] fputcsv no commas?

[code=php]$list = array (“$logtime”, “$vname”, “$addr”, “$addr2”, “$city”, “$state”, “$zip”, “$vemail”, “$vphone”, “$ip”);
$datafile= “_datalog.csv”;
$fp = fopen($datafile, “a”);
foreach ($list as $line)
{
fputcsv($fp, split(‘,’, $line));
}
fclose($fp); [/code]

I have this code basically copied from php.net, but when I execute it the resulting csv file has no commas in it. Where commas should be are line feeds (0a). Where am I going wrong?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SyCoJan 15.2009 — Run this perhaps you'll see more clearly whats happening to the values

[code=php]<?
$list = array ("a,1,2", "b,1,2", "c,1,2", "d,1,2", "e,1,2");
$datafile= "_datalog.csv";
$fp = fopen($datafile, "a");
foreach ($list as $line)
{
fputcsv($fp, split(',', $line));
}
fclose($fp);

?>[/code]


BTW you don't need to put the variables in double quotes.
Copy linkTweet thisAlerts:
@DasherauthorJan 15.2009 — Ah interesting.

I dumped the fputcsv and just went with fwrite added single quotes around each variable, and double quotes around the whole set of variables, and now it works like I want it too.

My whole list was intended to be a single row of csv fields. They are now.
×

Success!

Help @Dasher spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...