<?php
$a="This string will $print.\nAnd this is another line.";
echo $a;
?>
程序的输入结果为什么是 This string will . And this is another line.
而不是
This string will .
And this is another line. 呢?
教材上面明明写的是后者啊!
而且我把\n换为\t或者\r输出结果是一样的,三个符号只是起到了空格的作用,而不是应有的换行、制表、回车的功能,为什么呢?恳请高手指点,谢谢!
$a="This string will $print.\nAnd this is another line.";
echo $a;
?>
程序的输入结果为什么是 This string will . And this is another line.
而不是
This string will .
And this is another line. 呢?
教材上面明明写的是后者啊!
而且我把\n换为\t或者\r输出结果是一样的,三个符号只是起到了空格的作用,而不是应有的换行、制表、回车的功能,为什么呢?恳请高手指点,谢谢!
————————————————————————————————
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)[/size]
<?php
$a="This string will $print."."\n"."And this is another line.";
echo $a;
?>
<?php
$a="This string will $print.\nAnd this is another line.";
echo $a;
?>
</pre>
$a="This string will $print.\n<br />And this is another line.";
echo $a;
?>
一定是你要的结果
回复3楼:<BR>肯定可以,这没问题,关键是想弄清楚问什么\n \r \t不起作用,其它语言里面都可以。
回复8楼:按照大侠的指示,加上<pre> </pre>确实起作用了,能给大家解释一下问什么吗?
在html里, 回车/tab/空格 这些都叫做whitespace,
任何多个连续的whitespace在html都被显示为"一个空格"这就是这么规定的...<pre>里会原样显示这些字符也就是这么规定的,所以说要看html的书....如果要显示很多空格怎么办.... 楼上说了,
如果要回车... <br/> <p>等
如果要tab, ....如果你要显示表格最好是<table>, 或者<li>有时也行
更好的方法是用css控制你的显示为什么没说<pre>,这个tag比较特殊,如果你不是真的只要显示纯文本,就不该用html的显示的一般文本的显示是两回事....所以叫"超"文本