Line break in a textarea and create array using php

To add line breaks in html we have to use tags but to add this line break to any text entry from a form or from a text area we have to use the function nl2br() in PHP. This function nl2br() searches for all the line breaks or carriage returns within a string and replace them with line break tag or tag. This way we can automatically add line breaks for a web page inside a string after break line and use explode function and create array. You may also like Line breaks in a textarea using php and Read text file draw line between two points google map API using javascript.

PHP Code

$Item           = $_POST['item'];
$getitem        = nl2br($Item);
$haystack       = explode('<br />',$getitem);
$trimmed_array  = array_map('trim',$haystack);

Leave a Reply

Your email address will not be published. Required fields are marked *