rjanak Posted May 1, 2010 Share Posted May 1, 2010 Just started a book today on PHP and I have no other programming knowledge. I'm stuck on a very early example in the book though. Unless I'm reading it wrong, they say <<<_END..._END; should interpret everything inside it literally. So I'm not understanding why when I run the following example, the text is not put on new lines. <?php $author = "rjanak"; echo <<<_END This is a Headline This is the first line. This is the second. - Written by $author. _END; ?> From what I think the book is saying is that it should appear as follows... This is a Headline This is the first line. This is the second. - Written by rjanak. ... but it is appearing like this... This is a Headline This is the first line. This is the second. - Written by rjanak. Thanks in advance for the help... I don't want to continue until I understand it! (Using OS X, MAMP, NetBean. All latest versions.) Link to comment https://forums.phpfreaks.com/topic/200341-complete-beginner-help/ Share on other sites More sharing options...
foobarbaz Posted May 1, 2010 Share Posted May 1, 2010 If you viewed it via console or wrapped in <pre> tags you would see the newlines, Otherwise you can use this function nl2br to show it in browser. Newlines simply aren't converted by the browser by default into anything useful. Link to comment https://forums.phpfreaks.com/topic/200341-complete-beginner-help/#findComment-1051381 Share on other sites More sharing options...
liamthebof Posted May 1, 2010 Share Posted May 1, 2010 $author = "rjanak"; echo <<<_END <pre> This is a Headline This is the first line. This is the second. - Written by $author. </pre> _END; Outputs what you require. Link to comment https://forums.phpfreaks.com/topic/200341-complete-beginner-help/#findComment-1051473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.