andain Posted September 28, 2005 Report Share Posted September 28, 2005 lieta taada, ka vaidzeetu garos vardus vienk saiisinat: aaaaaaaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaa... izmeklejos google par wordwrapu - nedereeja nekas. pec tam iemegjinaju preg_replace: <?php function wordLimit($string, $length = 50, $ellipsis = '...') { return count($words = preg_split('/\s+/', ltrim($string), $length + 1)) > $length ? rtrim(substr($string, 0, strlen($string) - strlen(end($words)))) . $ellipsis : $string; } function stringLimit($string, $length = 50, $ellipsis = '...') { return strlen($fragment = substr($string, 0, $length + 1 - strlen($ellipsis))) < strlen($string) + 1 ? preg_replace('/\s*\S*$/', '', $fragment) . $ellipsis : $string; } echo wordLimit(' You can limit a string to only so many words.', 6); // Output: "You can limit a string to..." echo stringLimit('Or you can limit a string to a certain amount of characters.', 32); // Output: "Or you can limit a string to..." ?> bet tiklidz meginaju pie stringLimit pielikt kadu mainigo, piemeeram, $text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";echo stringLimit($text, 32) lapaa paraadas tikai ... varbut kads var palidzet vai arii ieteikt kko vienkarshaku? thx Link to comment Share on other sites More sharing options...
goldy Posted September 28, 2005 Report Share Posted September 28, 2005 ja vienkaarsi saiisinaat tad: substr($garsh_vards, 0, $vajadziigais_garums); Link to comment Share on other sites More sharing options...
andain Posted September 28, 2005 Author Report Share Posted September 28, 2005 paldies :) tik vel viens sikums: kaa pie saisinata varda beigas piemest klaat ...? Link to comment Share on other sites More sharing options...
bubu Posted September 28, 2005 Report Share Posted September 28, 2005 $text = $text . '...'; Link to comment Share on other sites More sharing options...
Recommended Posts