note 44239 deleted from function.substr by aidan
| From: | aidan@php.net | Date: | Sun, 22 Aug 2004 11:18:35 +0000 |
| Subject: | note 44239 deleted from function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75096@lists.php.net to get a copy of this message | ||
Note Submitter: janklopper on innerheight com
----
Easy to use string colapse function, choose to colapse the end,begin or center.
<?
function str_colapse($string,$length=150,$side="center",$filler="[....]"){
// $length= maximum length of string.
// side= side to cut chars off, center places .. in the center.
// filler is the strning used to indicate chopped of chars.
$strlength=strlen($string);
if($strlength>$length){
if($side=="right" or $side=="end"){
$tmpstring=substr($string,0,($length-strlen($filler))).$filler;
} elseif($side=="left" or $side=="begin"){
$tmpstring=$filler.
substr($string,
($strlength-($length-strlen($filler))),
($length-strlen($filler)));
} elseif($side=="center" or $side=="middle"){
$firstlength=ceil(($length/100)*20);
$tmpstring=substr($string,0,$firstlength).$filler.
substr($string,
($strlength-($length-($firstlength+strlen($filler)))),
($length-($firstlength+strlen($filler))));
}
return $tmpstring;
} else {
return $string;
}
}
?>