note 83585 deleted from function.substr by googleguy

From: Date: Tue, 16 Oct 2012 11:57:32 +0000
Subject: note 83585 deleted from function.substr by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191328@lists.php.net to get a copy of this message
Note Submitter: serzh at nm dot ru ---- easy and quick way to limit length of a text by not cutting full words: textLimit('some words', 7) is 'some...' <?php function textLimit($string, $length, $replacer = '...') { if(strlen($string) > $length) return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer; return $string; } ?>

« previous php.notes (#191328) next »