Paragraphs in textarea
Question
I have a form that has a textarea in it. How would I make new lines in the textarea appear as new paragraphs when I echo out the submitted textarea value?
Solution
<?php
$textarea = $_POST['textarea'];
$newarr = explode("\n",$textarea);
foreach($newarr as $str) {
echo "<p>".$str."</p>";
}
?>
OTHER TIPS
echo '<p>' . preg_replace("~[\r\n]+~", '</p><p>', $textarea) . '</p>';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow