note 87351 added to function.str-split
| From: | jesus at dunlock dot com | Date: | Mon, 01 Dec 2008 18:40:33 +0000 |
| Subject: | note 87351 added to function.str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147488@lists.php.net to get a copy of this message | ||
/* this one is working well
*
* @param $text to cut in pieces
* @param $n piece length
* @param(input/output) $ttab array object by reference
* @return $p pieces/pages
*
* by Xus; enjoy it!
*/
function divide_text($text, $n, &$ttab)
{
$ttab = array(); //array dividit
//removing spaces from
$text=ltrim(rtrim($text));
$l = strlen($text); // text length
$first = 0;
$p=0;
if ($l <= $n)
{
$ttab[] = $text;
return 1;
} else
{
while(strlen($text)>$n)
{
$tmp = substr($text, $first, $n);
// we're looking for last space in substring
$lastpos = strrpos($tmp," ");
//prevention from spaces between words
$ttab[] = rtrim(substr($text, $first, $lastpos));
$text=ltrim(substr($text, $lastpos, $l));
$p++;
}
$ttab[] = $text;
}
return $p;
}
----
Server IP: 130.206.1.5
Probable Submitter: 62.57.129.9
----
Manual Page -- http://www.php.net/manual/en/function.str-split.php
Edit -- https://master.php.net/note/edit/87351
Del: integrated -- https://master.php.net/note/delete/87351/integrated
Del: useless -- https://master.php.net/note/delete/87351/useless
Del: bad code -- https://master.php.net/note/delete/87351/bad+code
Del: spam -- https://master.php.net/note/delete/87351/spam
Del: non-english -- https://master.php.net/note/delete/87351/non-english
Del: in docs -- https://master.php.net/note/delete/87351/in+docs
Del: other reasons-- https://master.php.net/note/delete/87351
Reject -- https://master.php.net/note/reject/87351
Search -- https://master.php.net/manage/user-notes.php