Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个表格,里面有一个文本区域。当我回显提交的 textarea 值时,如何使 textarea 中的新行显示为新段落?
<?php $textarea = $_POST['textarea']; $newarr = explode("\n", $textarea); foreach($newarr as $str) { echo "<p>".$str."</p>"; } ?>
使用nl2br功能:
nl2br
<?php echo nl2br($_POST['textarea']); ?>
它将打印<br>所有换行符
<br>
echo '<p>' . preg_replace("~[\r\n]+~", '</p><p>', $textarea) . '</p>';