How to write tab characters in files using PHP
P粉399585024
P粉399585024 2023-10-16 15:49:49
0
2
630

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.

  • Real tab means, When we press the key in a text editor, we get a real wide space.


P粉399585024
P粉399585024

reply all(2)
P粉826283529

Use \t and enclose the string with double-quotes:

$chunk = "abc\tdef\tghi";
P粉121447292

The tab character is \t. Notice the use of " instead of '.

$chunk = "<html>\t<head>\t\t<title>\t</head>";

PHP String - Double Reference


Also, let me recommend the fputcsv() function, which is used to write CSV files.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template