doutangdan3588 2014-03-31 01:36
浏览 160

为什么我的php输出都在一行? [关闭]

Both these inputs get outputted as a single line.

I'm doing it just as my book shows. According to my book, these formats should respect all the whitespace and linebreaks without having to do the crap.

<?php 
$author = "Alfred E Newman"; 

echo <<<_END 
This is a Headline 

This is the first line. 
This is the second. 
- Written by $author. 
_END; 
?> 

<?php 
$author = "Alfred E Newman"; 
$text = "This is a Headline 

This is the first line. 
This is the second. 
Written by $author."; 
echo $text 
?> 

EDIT here' i'll quote my book on what it says this block of code should do " PHP also offers a multiline sequence using the <<< operator, commonly referred to as a here-doccument or heredoc for short. This is a way of specifying a string literal, preserving the line breaks and other whitespace (including indentation) in the text. Its use can be seen in Example 3-8." Eg.3-8 would be the first piece of code I posted on here. The book I'm using is, "Learning PHP, MySQL, JavaScript, and CSS" by Robin Nixon

ANOTHER EDIT Okay this is weird, I copy and pasted the Example #2 for the heredoc example on from the PHP manual into my PHP IDE and got the same result when the output should obviously be different "http://www.php.net/manual/en/language.types.string.php"

perhaps it's my IDE? I am running WAMP and everything seemed to be running fine until now...

EDIT AGAIN zomfg i hate when this happens, later on in the book he says it's normal because HTML formatting rules take over and white space is supprpessed" My bad guys. TBH, I don't see the point of it being only visible in the source page but not being formatted with the new lines. What good use is that when you can just open the original file and see it for yourself with the

  • 写回答

4条回答 默认 最新

  • doupeng3501 2014-03-31 01:43
    关注

    You can put it in a <pre> tag, otherwise you need <br> tags for HTML to recognise newlines.

    echo "<pre>$text</pre>";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能