I often have to show a shortened version of a news item and then a link to show the entire news article or whatever.

Here’s a way to get that short text!

[code lang=”php”]
function shortText($text, $length) {
if( strlen($text) > $length ) return substr(preg_replace(“/(<\/?)(\w+)([^>]*>)/”, “”, $text), 0, $length).”…”;
return preg_replace(“/(<\/?)(\w+)([^>]*>)/”, “”, $text);
}
[/code]