For anyone else who is interested.
turned it into a nice function, which also checks if the string is less than the amount of chars so it dont add ... to short strings
(in the situation im using it its in a loop getting the strinfs from a database so it helps  )
PHP Code:
<?php function shorten_txt($text, $cutpos) { # $cutpos = 8; // maximum length of character string # $text = 'the cat sat on the mat'; if(strlen($text) > $cutpos) { $output = substr($text,0,$cutpos); // find position of last space in extract $lastSpace = strrpos($output,' '); // use $lastSpace to set length of new extract and add ... return substr($output, 0, $lastSpace)."..."; } else { return $text; } } ?>
__________________
Discounted Web Hosting With XDnet! >> Get 25% of hosting~ Promo: Webmaster-talk <<
|