Published in: PHP
URL: http://es.php.net/manual/es/function.substr.php#63230
If you want to substring the middle of a string with another and keep the words intact:
function strMiddleReduceWordSensitive ($string, $max = 50, $rep = '[...]') { if ($strlen <= $max) return $string; $start = 0; $end = 0; if (($lengthtokeep % 2) == 0) { $start = $lengthtokeep / 2; $end = $start; } else { $end = $start + 1; } $i = $start; $tmp_string = $string; while ($i < $strlen) { if ($tmp_string[$i] == ' ') { $return = $tmp_string; } $i++; } $i = $end; while ($i < $strlen) { if ($tmp_string[$i] == ' ') { } $i++; } return $return; }
You need to login to post a comment.
