PHP 在文件中写入制表符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11055153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP to write Tab Characters inside a file?
提问by u775856
How do i simply write out a file including real tabs inside? tabmeans real tabwhich is not the spaces. How to write the tabor what is the character for real tab?
我如何简单地写出一个包含真实标签的文件?tab意味着真正tab的不是空格。如何写出tab真实的人物或人物是tab什么?
For example here:
例如这里:
$chunk = "a,b,c";
file_put_contents("chunk.csv",$chunk);
What character should i use to get tabsinstead of Commas (,)there?
In the output file, there should be real tabsbetween the seperated words.
我应该使用什么字符来tabs代替Commas (,)那里?
在输出文件中,tabs分隔的单词之间应该有real 。
- Real Tabs means, a true wide space we get when we press the
<tab>keyin a text-editor.
- 真正的标签意味着,当我们
<tab>在文本编辑器中按下键时,我们会得到一个真正的宽阔空间。
回答by kapa
The tab character is \t. Notice the use of "instead of '.
制表符是\t. 注意使用"代替'。
$chunk = "abc\tdef\tghi";
If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters:
...
\t horizontal tab (HT or 0x09 (9) in ASCII)
如果字符串用双引号 (") 括起来,PHP 将为特殊字符解释更多的转义序列:
...
\t 水平制表符(ASCII 中的 HT 或 0x09 (9))
Also, let me recommend the fputcsv()function which is for the purpose of writing CSV files.
另外,让我推荐用于编写 CSV 文件的fputcsv()函数。
回答by flowfree
Use \tand enclose the string with double-quotes:
使用\t双引号将字符串括起来:
$chunk = "abc\tdef\tghi";

