note 52914 added to function.explode

From: Date: Tue, 17 May 2005 15:15:25 +0000
Subject: note 52914 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-89552@lists.php.net to get a copy of this message
Here's Urban Heroes' function written with the ternary operator an dan inline assignment to make it slimmer still: function word_limit($string, $length = 50, $ellipsis = "...") { return (count($words = explode(' ', $string)) > $length) ? implode(' ', array_slice($words, 0, $length)) . $ellipsis : $string; } ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52914 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52914&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52914&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52914&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52914&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52914&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52914&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89552) next »