comment box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
amirbwb
Forum Commoner
Posts: 89
Joined: Sat Oct 30, 2010 6:10 pm

comment box

Post by amirbwb »

hello, i'm trying to create a comment, so everything works fine but i have a prob:
When i enter the comment in the comment box and write:
"
test test 123
test
test
"
in the page wich shows the comment this will appear "test test 123 test test" with to "return new line"
but actually i pressed "enter" 2 times
so ishould write the comment like this:
"
<p>test test 123</p>
<p>test</p>
<p>test</>
"

thank for your helps ..
User avatar
lorenzo-s
Forum Commoner
Posts: 43
Joined: Tue Aug 25, 2009 12:25 pm

Re: comment box

Post by lorenzo-s »

Type the comment the normal way, then print out the comment with:

Code: Select all

echo nl2br(htmlentities($comment));
I recommend you to read the docs for these functions and something about security and input escaping:
http://php.net/manual/en/function.nl2br.php
http://php.net/manual/en/function.htmlentities.php
http://www.mt-soft.com.ar/2007/12/21/th ... -mistakes/
Post Reply