0

I'm trying to create a variable with multiple lines but for some reason the <<<_END operator isn't working this is how the code looks:

<?php
$author = "Anon";
echo 
<<<_END
First Lines
Second Line.
Third Line.
- Written by $author.
_END;
?>

Why might it be?
I'm using php 5.2.14
on bitnami

not on my main computer but I will be using this pc for a good while so i need to fix that problem :p
Thanks!

2
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by terabyte
0

When I try it on the browsers all the text shows up in one line

1

Thats because newline characters are not the same as <br />. They are also not displayed on the output of the browser.

If you view the source of that output you will see that the text is actually on multiple lines.

0

thank you very much
seems I will have to keep using <br />

Edited by terabyte: n/a

1

You have another option if you want to still use heredoc:

<?php
$author = "Anon";
echo 
$str = <<<_END
First Lines
Second Line.
Third Line.
- Written by $author.
_END;

echo nl2br($str);
?>

nl2br inserts <br /> tags before any new line characters in the string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.