I’ve got a string like this:
I love @kevinrose 's new website <a href="http://kevinrose.com">Link</a>
And I have this function:
function short($string, $max = 255) {
if (strlen($string) >= $max) {
$string = mb_substr($string, 0, $max - 5, 'utf-8') . '...';
} return $string;
}
If I cut the screen at 50, it will end up being something that :
I love @kevinrose 's new website <a href="http://kevinr...
Which will of course kill the html.
Is there an easy way I can avoid cutting the a href tag (before or preferably after) without breaking the HTML ?
I need to keep my tags of course.
Thank you
see this from PHP: Truncate string while preserving HTML tags and whole words – Alan Whipple -> http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/
also see here
http://www.pjgalbraith.com/2011/11/truncating-text-html-with-php/