note 82671 added to function.wordwrap
| From: | ivan dot chura at gmail dot com | Date: | Mon, 21 Apr 2008 12:40:28 +0000 |
| Subject: | note 82671 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138613@lists.php.net to get a copy of this message | ||
This function can be useful for wrap string by specify chars, not only space char.
<?php
/**
* Wrap string by specify chars
*
* @param string $strForWrap
* @param integer $maxLength
* @param string $breakChar
* @param array $wrapChars
*
* @author Ivan Chura
* @since 21.04.2008
* @return string
**/
function wordwrapBySpecifyChars($strForWrap, $maxLength = 80, $breakChar = "\n",
$wrapChars = array(",", ";" ))
{
$newStr = null;
$length_of_string = strlen($strForWrap);
if ($length_of_string <= $maxLength)
{
return $strForWrap;
}
$count_of_string = 1;
$wait_new_line = false;
for($i=0; $i<$length_of_string; $i++)
{
if ( $count_of_string*$maxLength == $i || $wait_new_line)
{
if (in_array($strForWrap{$i}, $wrapChars ) )
{
$count_of_string ++;
$newStr .= $strForWrap{$i}.$breakChar;
$wait_new_line = false;
}
else
{
$newStr .= $strForWrap{$i};
$wait_new_line = true;
}
}
else
{
$newStr .= $strForWrap{$i};
}
}
return $newStr;
}
?>
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/82671
Del: integrated -- https://master.php.net/note/delete/82671/integrated
Del: useless -- https://master.php.net/note/delete/82671/useless
Del: bad code -- https://master.php.net/note/delete/82671/bad+code
Del: spam -- https://master.php.net/note/delete/82671/spam
Del: non-english -- https://master.php.net/note/delete/82671/non-english
Del: in docs -- https://master.php.net/note/delete/82671/in+docs
Del: other reasons-- https://master.php.net/note/delete/82671
Reject -- https://master.php.net/note/reject/82671
Search -- https://master.php.net/manage/user-notes.php