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!

any help :p

bump

What aspect of that is not working for you? That code works fine for me.

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

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.

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

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.

Thanks mate it worked perfectly!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.