[php] PHP to write Tab Characters inside a file?

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.

This question is related to php string csv tsv

The answer is


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

$chunk = "abc\tdef\tghi";

This should do:

$chunk = "abc\tdef\tghi";

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


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to string

How to split a string in two and store it in a field String method cannot be found in a main class method Kotlin - How to correctly concatenate a String Replacing a character from a certain index Remove quotes from String in Python Detect whether a Python string is a number or a letter How does String substring work in Swift How does String.Index work in Swift swift 3.0 Data to String? How to parse JSON string in Typescript

Examples related to csv

Pandas: ValueError: cannot convert float NaN to integer Export result set on Dbeaver to CSV Convert txt to csv python script How to import an Excel file into SQL Server? "CSV file does not exist" for a filename with embedded quotes Save Dataframe to csv directly to s3 Python Data-frame Object has no Attribute (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape How to write to a CSV line by line? How to check encoding of a CSV file

Examples related to tsv

PHP to write Tab Characters inside a file?