How do I simply write out a file containing real tabs? tab
represents the real tab
, which is not a space. How to write tab
or what characters are the real tab
?
For example here:
$chunk = "a,b,c"; file_put_contents("chunk.csv",$chunk);
What characters should I use to get tabs
instead of comma (,)
there?
In the output file, there should be real tabs
between delimited words.
key in a text editor, we get a real wide space. P粉8262835292023-10-17 15:05:36
Use \t
and enclose the string with double-quotes:
$chunk = "abc\tdef\tghi";
P粉1214472922023-10-17 14:01:25
The tab character is \t
. Notice the use of "
instead of '
.
$chunk = "<html>\t<head>\t\t<title>\t</head>";
Also, let me recommend the fputcsv() function, which is used to write CSV files.