note 84775 deleted from function.substr by peehaa
| From: | peehaa@php.net | Date: | Mon, 28 Nov 2016 19:47:10 +0000 |
| Subject: | note 84775 deleted from function.substr by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207719@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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;
}
?>