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
testing
Leave a Reply



(Your email will not be publicly displayed.)

Please type the letters and numbers shown in the image.Captcha Code