我有一些来自<textarea>
的用户提交的数据。然后,我有一些代码在上面插入评论。有点像这样....
$my_comment = 'stuff from me';
$user_comment = $_POST['user_comment'];
$full_comment = $my_comment . 'nn' . $user_comment;
之后,将$full_comment
插入到DB中。后来,它将从DB中拉出并放入<textarea>
中。我希望nn
实际上像新行一样起作用,但是它们实际上在新的<textarea>
中显示为" n n"。
我如何使nn
正确功能?
顺便说一句,我已经知道表单验证,PDO等。这只是示例代码。
您可以使用htmlentities
功能。
$full_comment = $my_comment . 'nn' . $user_comment;
$full_comment = htmlentities( $full_comment );
也 如果必要
$full_comment = stripslashes( htmlentities( $full_comment ) );