PHP在文件中写入Tab字符? [英] PHP to write Tab Characters inside a file?

查看:1976
本文介绍了PHP在文件中写入Tab字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何简单地写出一个包含真正标签的文件? 标签表示真实的标签,这是而不是空格。如何编写标签或真实标签的字符?



例如:

  $ chunk =a,b,c 
file_put_contents(chunk.csv,$ chunk);

我应该使用什么字符来获取标签而不是 Commas(,)有?

在输出文件中,应该有真实的 tabs


  • Real Tabs意味着当我们按下

解决方案

制表符字符为 \t 。请注意使用而不是'

  $ chunk =abc\tdef\tghi; 

PHP字符串 - 双引号


如果字符串包含在双引号()中,PHP会解释
更多转义序列字符:



...



\水平标签(HT或0x09(9)







此外,让我推荐 fputcsv()函数,用于写入CSV文件。


How do i simply write out a file including real tabs inside? tab means real tab which is not the spaces. How to write the tab or what is the character for real tab?

For example here:

$chunk = "a,b,c";
file_put_contents("chunk.csv",$chunk);

What character should i use to get tabs instead of Commas (,) there?
In the output file, there should be real tabs between the seperated words.

  • Real Tabs means, a true wide space we get when we press the <tab> key in a text-editor.

解决方案

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

$chunk = "abc\tdef\tghi";

PHP Strings - Double quoted

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)


Also, let me recommend the fputcsv() function which is for the purpose of writing CSV files.

这篇关于PHP在文件中写入Tab字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆