I\'m pulling blog posts from a DB. I want to trim the text to a max length of 340 characters.
If the blog post is over 340 characters I want to trim the text to the las
Simplest solution
$text_to_be_trim= "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard.";
if(strlen($text_to_be_trim) > 20)
$text_to_be_trim= substr($text_to_be_trim,0,20).'....';
For multi-byte text
$stringText= "UTIL CONTROL DISTRIBUCION AMARRE CIGÜEÑAL";
$string_encoding = 'utf8';
$s_trunc = mb_substr($stringText, 0, 37, $string_encoding);
echo $s_trunc;