Mr.x Posted July 8, 2006 Share Posted July 8, 2006 Hello Everyone,Just wondering if anyone knows a way so that say I have a script that prints out a result from a database and its result is more then 10 char, to stop on char 10 and add ... ie.applecherrybanana <- Normalapplecherry... <- AfterThanks alot,Sean Quote Link to comment https://forums.phpfreaks.com/topic/14007-if-more-than-10-char-replace-with/ Share on other sites More sharing options...
Crimpage Posted July 8, 2006 Share Posted July 8, 2006 [code]function nicetrim ($s, $l) {// limit the length of the given string to $MAX_LENGTH char// If it is more, it keeps the first $MAX_LENGTH-3 characters // and adds "..."// It counts HTML char such as á as 1 char.// $MAX_LENGTH = $l; $str_to_count = html_entity_decode($s); if (strlen($str_to_count) <= $MAX_LENGTH) { return $s; } $s2 = substr($str_to_count, 0, $MAX_LENGTH - 3); $s2 .= "..."; return htmlentities($s2);}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14007-if-more-than-10-char-replace-with/#findComment-54693 Share on other sites More sharing options...
Mr.x Posted July 8, 2006 Author Share Posted July 8, 2006 Thank you very much :) Quote Link to comment https://forums.phpfreaks.com/topic/14007-if-more-than-10-char-replace-with/#findComment-54694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.