I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage. The original block of text can be a lengthy artic
Here is my function based on @Cd-MaN's approach.
function shorten($string, $width) { if(strlen($string) > $width) { $string = wordwrap($string, $width); $string = substr($string, 0, strpos($string, "\n")); } return $string; }