Jump to content

nl2br


mafkeesxxx

Recommended Posts

[quote author=Gruzin link=topic=109934.msg443556#msg443556 date=1159520582]
Here is a little example:

[code]<?php
$var = $_POST['mail']; // something from form
$mail =  // add nl2br to it
?>[/code]
[/quote]
WHy do people do that! I dont get it. Just do:
[code=php:0]$mail = nl2br($_POST['mail']);[/code]
Link to comment
Share on other sites

Ok, Thanks for all your help, but probably is a bit more complicated.
I have a mail form wich is HTML with mail.php included.

This results in a HTML template that is send via mail and recognises the form fields like this {Comments}

Now i want to apply the nl2br to the {Comments}

Damn, LOL  ;D ???

Hope you understand  :-\


Link to comment
Share on other sites

[quote author=Mutley]
[code]nl2br($comments)[/code]

Should work? You don't need to make it a variable.
[/quote]

I don't know what version of PHP you're using, but mine requires you to assign it to a variable, unless you're echoing it directly :D

[code]
<?php
$comments = <<<EOT
This is line one
This is line two
This is line three
EOT;

// This will print on one line
echo "$comments";

// This will print on one line
nl2br($comments);
echo "$comments";

// This will print on multiple lines
echo nl2br($comments);

// This will print on multiple lines
$comments = nl2br($comments);
echo "$comments";
?>
[/code]

Regards
Huggie
Link to comment
Share on other sites

The function nl2br() does not change the argument, it returns the modified string, so a statement like:
[code]<?php nl2br($str); ?>[/code]
by itself does not do anything. You need to either echo the result or assign the result to a variable.

Also, using double quotes around one variable when you're doing an echo are not needed. The following two statements will produce identical output:
[code]<?php echo "$string"; ?>[/code]
[code]<?php echo $string; ?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.