mafkeesxxx Posted September 29, 2006 Share Posted September 29, 2006 Hello!I have made a form with a comment field. Now i want to apply the [b]nl2br[/b] string to my comment field. I've tried some things, but didn't work. How can i do this? This is my HTML: <textarea name="Comments" cols="60" rows="15"></textarea>Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/ Share on other sites More sharing options...
hostfreak Posted September 29, 2006 Share Posted September 29, 2006 nl2br should be used when you want to print the line out to view it. Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100716 Share on other sites More sharing options...
mafkeesxxx Posted September 29, 2006 Author Share Posted September 29, 2006 The comment field will be send via e-mail.So i want to apply nl2br to the field, otherwise i recieve the mailed comment field without enters <br> Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100727 Share on other sites More sharing options...
Gruzin Posted September 29, 2006 Share Posted September 29, 2006 Here is a little example:[code]<?php$var = $_POST['mail']; // something from form$mail = nl2br($var); // add nl2br to it?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100729 Share on other sites More sharing options...
wildteen88 Posted September 29, 2006 Share Posted September 29, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100732 Share on other sites More sharing options...
Gruzin Posted September 29, 2006 Share Posted September 29, 2006 Well you are right wildteen88 :) Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100733 Share on other sites More sharing options...
hostfreak Posted September 29, 2006 Share Posted September 29, 2006 wildteen88, why does it matter? It is personal preference. It may not be the most efficient way, but it works. Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100734 Share on other sites More sharing options...
Gruzin Posted September 29, 2006 Share Posted September 29, 2006 and it's easy to understand for noob ;) Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100737 Share on other sites More sharing options...
mafkeesxxx Posted September 29, 2006 Author Share Posted September 29, 2006 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 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100762 Share on other sites More sharing options...
JasonLewis Posted September 29, 2006 Share Posted September 29, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100782 Share on other sites More sharing options...
mafkeesxxx Posted September 29, 2006 Author Share Posted September 29, 2006 [b]Ok, still doens't work, this is my mailscript. Hope you can help me now! :)[/b][code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100848 Share on other sites More sharing options...
HuggieBear Posted September 29, 2006 Share Posted September 29, 2006 [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 = <<<EOTThis is line oneThis is line twoThis is line threeEOT;// This will print on one lineecho "$comments";// This will print on one linenl2br($comments);echo "$comments";// This will print on multiple linesecho nl2br($comments);// This will print on multiple lines$comments = nl2br($comments);echo "$comments";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100856 Share on other sites More sharing options...
mafkeesxxx Posted September 29, 2006 Author Share Posted September 29, 2006 @HuggieBearThanks,But i don't know how to apply it to the script i posted above. Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100858 Share on other sites More sharing options...
kenrbnsn Posted September 29, 2006 Share Posted September 29, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100860 Share on other sites More sharing options...
kenrbnsn Posted September 29, 2006 Share Posted September 29, 2006 Find this line in your code:[code]<?php $MailBody = $TemplateData;?>[/code]replace it with:[code]<?php $MailBody = nl2br($TemplateData);?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100862 Share on other sites More sharing options...
mafkeesxxx Posted September 29, 2006 Author Share Posted September 29, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/22467-nl2br/#findComment-100883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.