Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created May 19, 2014 17:06
Show Gist options
  • Save ChrisLTD/5b50392d3204cc2441fe to your computer and use it in GitHub Desktop.
Save ChrisLTD/5b50392d3204cc2441fe to your computer and use it in GitHub Desktop.
<?php
function truncate_with_end ($string, $max = 200, $rep = '') {
$len = strlen ($string);
if( $len <= $max ){
return $string;
}
$leave = $max - strlen ($rep);
return substr_replace($string, $rep, $leave);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment