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
https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100732
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
https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100762
Share on other sites

ok. first off. what the others said is correct. {Comments} would be a variable.

so you would do:
[code]$comments = nl2br($comments);[/code]

or you could do this, but its easier to do the above:

[code]$comments = str_replace("\n", "<br>", $comments);[/code]
Link to comment
https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100782
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
https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100856
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
https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100860
Share on other sites

[quote author=kenrbnsn link=topic=109934.msg443693#msg443693 date=1159538318]
Find this line in your code:
[code]<?php
$MailBody =  $TemplateData;
?>[/code]
replace it with:
[code]<?php
$MailBody =  nl2br($TemplateData);
?>[/code]

Ken
[/quote]

Thanks dude, Just what i needeed!

It works  ;D
Link to comment
https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100883
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.