shortText function toggler in php
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!
function shortText($text, $length) {
if( strlen($text) > $length ) return substr(preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $text), 0, $length)."…";
return preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $text);
}
if( strlen($text) > $length ) return substr(preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $text), 0, $length)."…";
return preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $text);
}
Trackbacks
There are no trackbacks on this entry.

Comments
There are no comments on this entry.