|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2002-05-07 01:44 UTC] mfischer@php.net
  [2002-05-30 04:07 UTC] mj@php.net
  [2002-10-20 15:55 UTC] iliaa@php.net
  [2010-12-01 16:11 UTC] jani@php.net
 
-Status:  Analyzed
+Status:  Wont fix
-Package: Feature/Change Request
+Package: *General Issues
  [2010-12-01 16:11 UTC] jani@php.net
 | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 12:00:01 2025 UTC | 
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.