简体   繁体   English

nl2br显示文本区域

[英]nl2br to display textarea

I am implementing a contact form. 我正在填写联系表格。 When the user submits the form, all input is validated and stored in a session. 当用户提交表单时,所有输入都会被验证并存储在会话中。 It is then forwarded to a page that informs the user of a successfully posting of the comment, displaying the data entered. 然后将其转发到一个页面,该页面通知用户已成功发布评论,并显示输入的数据。

The trouble I am having is that all new lines are not being displyed correctly as breaks using nl2br() . 我遇到的麻烦是,使用nl2br()中断时,所有新行都无法正确显示。

User input: 用户输入:

<textarea name="comments" rows="10" cols="50" id="comments" tabindex="5" title="comments"> <?php echo isset($_POST['comments']) ? $_POST['comments'] : ''; ?>

when validated... 验证后...

$_SESSION['comments'] = $_POST['comments'];

forwarded on to contact-sent page and then appended to the string to display 转发到联系人发送的页面,然后附加到字符串以显示

$forwardString = "<h2>New Website Comment: </h2><h3>" . $cEmail . "</h3><p>" . $cComment . "</p>";

Then displayed: 然后显示:

echo nl2br($forwardString);

Where do I implement the nl2br() function? 我在哪里实现nl2br()函数?

Example input: 输入示例:

Just a test to verify contact works correctly.

We should see two line breaks here.
One line break here

Currently yields: 目前产量:

Just a test to verify contact works correctly.We should see two line breaks here.One line break here

try 尝试

echo nl2br(stripslashes($forwardString));

You could be possibly escaping the string twice so the \\n becomes \\n 您可能会两次转义字符串,因此\\ n变为\\ n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM