note 48773 added to function.substr-replace
| From: | tekrat at 2d dot com | Date: | Thu, 06 Jan 2005 16:55:46 +0000 |
| Subject: | note 48773 added to function.substr-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82850@lists.php.net to get a copy of this message | ||
Here's a slightly revised version of the truncation function above.
Theres isn't much of a reason to add in the $rep at the end of the original string is less
then the truncation break point.
<?
function truncate($substring, $max = 50, $rep = '...') {
if(strlen($substring) < 1){
$string = $rep;
}else{
$string = $substring;
}
$leave = $max - strlen ($rep);
if(strlen($string) > $max){
return substr_replace($string, $rep, $leave);
}else{
return $string;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.substr-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48773
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48773&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48773&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48773&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48773&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48773&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48773&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48773&report=yes
Search -- http://master.php.net/manage/user-notes.php