note 39290 added to function.split
| From: | ferg at voidstate dot com | Date: | Fri, 23 Jan 2004 09:41:45 +0000 |
| Subject: | note 39290 added to function.split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64058@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.split.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39290
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39290&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39290&report=yes
Search -- http://master.php.net/manage/user-notes.php