function truncate_string($string, $max_length){ if (strlen($string) > $max_length) { $string = substr($string,0,$max_length); $string .= '...'; } return $string; } |
Here is a function that will truncate strings length.
example:
<?php $string = "this is a test, this string will be shorten."; echo truncate_string($string, 5); ?> |
output: this ...
Comments:
Posted by
admin
on
Jun 1st, 2010
testing