note 39290 deleted from function.split by nlopess

From: Date: Fri, 23 Jan 2004 19:10:41 +0000
Subject: note 39290 deleted from function.split by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64076@lists.php.net to get a copy of this message
Note Submitter: ferg@voidstate.com ---- To split the data sent from a textarea into paragraphs everytime there is at least two newlines (regardless of whitespace), the following function works: function addParagraphTags( $text ) { $textElements = split ("( |\n|\t|\r)*([\n|\r\n|\r]( |\n|\t|\r)*[\n|\r\n|\r]{2,})( |\n|\t|\r)*", $text); $newText = ""; foreach ($textElements as $item) { $item = trim ( $item ); if ( strlen ( $item ) != 0 ) $newText .= "<p>$item</p>"; $text = $newText; } return $text; }

« previous php.notes (#64076) next »