How to best create breaks in a comment using PHP/MYSQL?
I've tried searching for this, but no luck. I have programmed a comment system using PHP and MYSQL and I am having problems displaying comments that users have breaked using enter. I currently have 开发者_如何学JAVAhtml blocked from all comments in order to submit a sanitized entry into MYSQL so they cannot use <br>
or anything like that.
I guess my question is this: Are there any special techniques to allow more freedom in the comments users post, especially if they hit enter for a break?
You can use nl2br
for this. Check the manual for more details.
You can do a
$input = str_replace("\n", "<br />", $input);
To manually put in the breaks before inputting to the database. Just make sure this happens after any strip_tags
or other validation.
精彩评论