note 100688 added to function.wordwrap
| From: | patigunjan at gmail dot com | Date: | Sun, 31 Oct 2010 08:50:25 +0000 |
| Subject: | note 100688 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173614@lists.php.net to get a copy of this message | ||
A small change to venimus's cutstr function below. If the upper bound is strict, adding
$ellipsis may cause the final string to be sometimes larger than the expected bound
Also added better defaults and changed to a more intuitive name (IMHO)
<?php
function stringWrap($str, $length, $ellipsis='...') {
$cut = (array) explode('\n\n', wordwrap($str , $length - strlen($ellipsis),
'\n\n'));
return $cut[0].(strlen($cut[0]) < strlen($str) ? $ellipsis : '');
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 117.196.188.10
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/100688
Del: integrated -- https://master.php.net/note/delete/100688/integrated
Del: useless -- https://master.php.net/note/delete/100688/useless
Del: bad code -- https://master.php.net/note/delete/100688/bad+code
Del: spam -- https://master.php.net/note/delete/100688/spam
Del: non-english -- https://master.php.net/note/delete/100688/non-english
Del: in docs -- https://master.php.net/note/delete/100688/in+docs
Del: other reasons-- https://master.php.net/note/delete/100688
Reject -- https://master.php.net/note/reject/100688
Search -- https://master.php.net/manage/user-notes.php