note 84104 deleted from function.strlen by danbrown
| From: | danbrown@php.net | Date: | Thu, 12 Feb 2009 03:12:03 +0000 |
| Subject: | note 84104 deleted from function.strlen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150531@lists.php.net to get a copy of this message | ||
Note Submitter: kyle dot florence ~at~ gmail dot com
----
Improved version of 'php at capcarrere dot org's "nicetrim" function:
<?
// Trim a string to specified legnth and append an end character (default = ...)
function str_trim($str, $lim = 32, $chr = '…')
{
// If length of string is less than $lim, return string
if (strlen($str = html_entity_decode($str)) <= $lim) return $str;
// Else, cut string down to size
return htmlentities(substr($str, 0, $lim - 3)).$chr;
}
?>