note 84775 modified in function.substr by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 20:13:31 +0000 |
| Subject: | note 84775 modified in function.substr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147189@lists.php.net to get a copy of this message | ||
I wrote this simple function to limit the middle characters of a string to a specified length.
<?php
$input = "hello world"
echo(limitchrmid($imput,10)) // hel ... rld
//limit chars middle
function limitchrmid($value,$lenght){
if (strlen($value) >= $lenght ){
$lenght_max = ($lenght/2)-3;
$start = strlen($value)- $lenght_max;
$limited = substr($value,0,$lenght_max);
$limited.= " ... ";
$limited.= substr($value,$start,$lenght_max);
}
else{
$limited = $value;
}
return $limited;
}
?>
--was--
I wrote this simple function
<?php
$input = "hello world"
echo(limitchrmid($imput,10)) // hel ... rld
//limit chars middle
function limitchrmid($value,$lenght){
if (strlen($value) >= $lenght ){
$lenght_max = ($lenght/2)-3;
$start = strlen($value)- $lenght_max;
$limited = substr($value,0,$lenght_max);
$limited.= " ... ";
$limited.= substr($value,$start,$lenght_max);
}
else{
$limited = $value;
}
return $limited;
}
?>
http://php.net/manual/en/function.substr.php