Count Character and DO NOT break word

$str = get_the_content();
$charset = ‘utf-8’;
$len = iconv_strlen($content, $charset);
$max_len = 97;
$max_cut_len = 10;
if ($len > $max_len)
{
$str = iconv_substr($str, 0, $max_len, $charset);
$prev_space_pos = iconv_strrpos($str, ‘ ‘, $charset);
if (($max_len-$prev_space_pos) < $max_cut_len) $str = iconv_substr($str, 0, $prev_space_pos, $charset);
$str .= ‘ …’;
}
echo $str;

Leave a Reply

Your email address will not be published.