How do I cut a string and add suspension marks?
I wan to cut a string in around 300 characters and add "..." at the end if开发者_如何学C it was above that number of characters. I know it can't be very hard but I don't want to cut a word in half so I wanted to know how do I do it so it doesn't end up like: "And the bird suddenl..."
Thanks
http://php.net/wordwrap
$str = 'A very long string here';
$str = wordwrap($str, 100);
$str = explode("\n", $str);
$str = $str[0] . '...';
function limit($str, $limit, $append = '...') {
return preg_replace('/\S*$/', '', mb_substr($str, 0, $limit)) . $append;
}
精彩评论