php 如何让php将\t\n显示为制表符和换行符而不是字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16066614/
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
How to make php display \t \n as tab and new line instead of characters
提问by Tamil Selvan C
I'm trying to output the data in my php file as plain text and I want the output to have a table format like this:
我正在尝试将我的 php 文件中的数据作为纯文本输出,并且我希望输出具有这样的表格格式:
data1 data2 data3
1 a b
2 c d
....
When i try this:
当我尝试这个时:
foreach(...)
echo $data1 . '\t' . $data2 . '\t' . $data3 . '\n';
it prints them as data1\tdata2\tdata3\n...
它将它们打印为 data1\tdata2\tdata3\n...
How can I get php to read \t
and \n
as tab and new line?
我怎样才能让 php 读取\t
并\n
作为选项卡和新行?
回答by Tamil Selvan C
put it in double quotes
把它放在双引号中
echo "\t";
echo "\t";
See: http://php.net/language.types.string#language.types.string.syntax.double
请参阅:http: //php.net/language.types.string#language.types.string.syntax.double
回答by Wesley Schleumer de Góes
"\n" = new line
'\n' = \n
"\t" = tab
'\t' = \t
回答by dave
"\t"
not '\t'
, php doesnt escape in single quotes
"\t"
不是'\t'
,php 不会在单引号中转义
回答by Sverri M. Olsen
Put it in double quotes:
把它放在双引号中:
echo "\t";
Single quotes do not expand escaped characters.
单引号不会扩展转义字符。
Use the documentationwhen in doubt.
如有疑问,请使用文档。
回答by Melki
You can use HTML,
您可以使用 HTML,
foreach(...)
echo $data1 . ' ' . $data2 . ' ' . $data3 . '<br/>';