Req #17057 [Ana->Wfx]: substr with pretty output
| From: | jani@php.net | Date: | Wed, 01 Dec 2010 15:11:47 +0000 |
| Subject: | Req #17057 [Ana->Wfx]: substr with pretty output | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156646@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=17057&edit=1
ID: 17057
Updated by: jani@php.net
Reported by: frank at vista dot com
Summary: substr with pretty output
-Status: Analyzed
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Linux (Redhat 7.2)
PHP Version: 4.1.2
Block user comment: N
Private report: N
New Comment:
This is something you implement yourself.
Previous Comments:
------------------------------------------------------------------------
[2002-10-20 15:55:48] iliaa@php.net
This is not a bug, rather a feature request.
------------------------------------------------------------------------
[2002-05-30 04:07:13] mj@php.net
Once there will be a Text/Word package, we will possibly realize
something like this. => Analyzed.
------------------------------------------------------------------------
[2002-05-07 01:44:47] mfischer@php.net
Since there was talk someone (Daniel??) will work in this for PEAR, I
reclassify this.
------------------------------------------------------------------------
[2002-05-06 21:04:10] frank at vista dot com
Often times you want to display the name of something in a list (say,
items in a store) but have limited space.
You can simply truncate strings that are longer than x characters and
add an ellipsis, but occasionally you end up with:
"The quick brown fox ..." or "The quick brown f...". When "The quick
brown fox..." or "The quick brown..." (respectively) would be nicer.
In PHP Code:
function pretty_substr($string, $length, $slop = 4) {
if (strlen($string) > $length) {
$string = substr($string, 0, $length - 1);
$lastSpace = strrpos($string, ' ');
if ($lastSpace > $length - $slop) {
$string = substr($string, 0, $lastSpace);
}
$string .= '…';
}
return $string;
}
I think this would make a good addition to the string function library.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=17057&edit=1