Search code examples
phptextareaparagraph

Paragraphs in textarea


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>";
    
        }
    ?>