PHP to write Tab Characters inside a file?

前端 未结 3 2130
梦谈多话
梦谈多话 2020-12-25 10:27

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 ta

相关标签:
3条回答
  • 2020-12-25 10:48

    This should do:

    $chunk = "abc\tdef\tghi";
    

    Here is a link to an article with more extensive examples.

    0 讨论(0)
  • 2020-12-25 10:49

    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.

    0 讨论(0)
  • 2020-12-25 10:58

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

    $chunk = "abc\tdef\tghi";
    
    0 讨论(0)
提交回复
热议问题