note 44239 added to function.substr
| From: | janklopperoninnerheightcom at rn2 dot php dot net | Date: | Mon, 19 Jul 2004 13:10:01 +0000 |
| Subject: | note 44239 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73601@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44239
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44239&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44239&report=yes
Search -- http://master.php.net/manage/user-notes.php