Concatinate Variable with line breaks

I am trying to concatenate a variable from form input and format the variable with new lines between the name, email address, phone # and message. The code is below:
[php]$comments=$_POST[‘first_name’]." “.$_POST[‘last_name’].”\n";
$comments .=$_POST[‘email’]."\n";
$comments .=$_POST[‘phone’]."\n";
$comments .=$_POST[‘comments’];[/php]
When the variable $comments prints, it is still all on one line. Can someone tell me what I did wrong?
Thanks

You need to use the break tag, not the newline character.

The newline use is good for when you view the souce of your html in the browser.

Why are you putting everything into comments? The only time I would do that is for formatting an email message. Other wise you can do like so…

[php]
echo $_POST[‘first_name’]." “.$_POST[‘last_name’].”
\n";
echo $_POST[‘email’]."
\n";
echo $_POST[‘phone’]."
\n";
echo $_POST[‘comments’];
[/php]

Actually I was trying to use the same variable for both the screen and an email.
I did finally code the screen message similar to your suggestion only I used the <br/> and not the [php]"\n"[/php].
In the email I finally changed the new line code to [php]"\r\n"[/php] and that worked.

Thanks for the advise.

Yes, in one line, the “/n” is “newline”, without a return. It is used for parsing text and not actually for showing a CRLF as you would think. CRLF means carriage-return followed by line-feed. So, “/r/n” is correct way to do it.
I usually just use
… Whatever works. Just wanted to explain it…

Thank you for the explanation.

Sponsor our Newsletter | Privacy Policy | Terms of Service