note 91473 added to function.fputcsv
| From: | alex/- | Date: | Thu, 11 Jun 2009 15:41:10 +0000 |
| Subject: | note 91473 added to function.fputcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156778@lists.php.net to get a copy of this message | ||
TAB delimiting.
Using fputcsv to output a CSV with a tab delimiter is a little tricky since the delimiter field only
takes one character.
The answer is to use the chr() function. The ascii code for tab is 9, so chr(9) returns a tab
character.
<?php
fputcsv($fp, $foo, '\t'); //won't work
fputcsv($fp, $foo, ' '); //won't work
fputcsv($fp, $foo, chr(9)); //works
?>
==================
it should be:
<?php
fputcsv($fp, $foo, "\t");
?>
you just forgot that single quotes are literal...meaning whatever you put there that's what
will come out so '\t' would be same as 't' because \ in that case would be only
used for escaping but if you use double quotes then that would work.
----
Server IP: 208.69.120.35
Probable Submitter: 68.161.247.230
----
Manual Page -- http://www.php.net/manual/en/function.fputcsv.php
Edit -- https://master.php.net/note/edit/91473
Del: integrated -- https://master.php.net/note/delete/91473/integrated
Del: useless -- https://master.php.net/note/delete/91473/useless
Del: bad code -- https://master.php.net/note/delete/91473/bad+code
Del: spam -- https://master.php.net/note/delete/91473/spam
Del: non-english -- https://master.php.net/note/delete/91473/non-english
Del: in docs -- https://master.php.net/note/delete/91473/in+docs
Del: other reasons-- https://master.php.net/note/delete/91473
Reject -- https://master.php.net/note/reject/91473
Search -- https://master.php.net/manage/user-notes.php