On Thursday 25 January 2001 21:06, H. Wade Minter wrote: > Does anyone have a good idea on how to split after a certain number of > words? Attached is code that semi-intelligently limits strings to a certain number of characters. Perhaps that helps you. -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) "use the source, luke." (obi-wan gnuobi)
<?php function LimitString ($TheString, $MaxChars, $Threshold = 5) { if (strlen ($TheString) <= $MaxChars) return $TheString; // (1) hard upper limit is $MaxChars $Work = substr ($TheString, 0, $MaxChars); // (2) try to find a word boundary at the end to make it look nicer $Pos = strrpos ($Work, ' '); if ($Pos >= ($MaxChars - $Threshold)) $Work = substr ($Work, 0, $Pos); $Work .= ' ...'; return $Work; } ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]