09-07-2007, 11:21 PM
|
#1 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Posts: 165
Thanks: 0
|
[Tip] Limiting a strings length
Below is a handy function for shortening a string, where space is needed...
PHP Code:
function limitString($szInput, $iLength=25, $szAffix='...') { if(strlen($szInput) <= $iLength) return $szInput;
$iLength = $iLength - strlen($szAffix);
return trim(substr($szInput, 0, $iLength)) . $szAffix); }
Example:
PHP Code:
$string = "This is a long string that should be shortened using our great function";
print limitString($string, 10, '...'); //Outputs "this is..."
Last edited by bluesaga : 09-08-2007 at 12:37 AM.
|
|
|
|