note 63996 added to function.str-word-count

From: Date: Wed, 05 Apr 2006 06:03:18 +0000
Subject: note 63996 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-107359@lists.php.net to get a copy of this message
There is a small bug in the "trim_text" function by "webmaster at joshstmarie dot com" below. If the string's word count is lesser than or equal to $truncation, that function will cut off the last word in the string. This fixes the problem: <?php function trim_text_fixed($string, $truncation = 250) { $matches = preg_split("/\s+/", $string, $truncation + 1); $sz = count($matches); if ( $sz > $truncation ) { unset($matches[$sz-1]); return implode(' ',$matches); } return $string; } ?> ---- Server IP: 203.199.124.111 Probable Submitter: 59.144.16.149 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.str-word-count.php Edit -- http://master.php.net/note/edit/63996 Del: integrated -- http://master.php.net/note/delete/63996/integrated Del: useless -- http://master.php.net/note/delete/63996/useless Del: bad code -- http://master.php.net/note/delete/63996/bad+code Del: spam -- http://master.php.net/note/delete/63996/spam Del: non-english -- http://master.php.net/note/delete/63996/non-english Del: in docs -- http://master.php.net/note/delete/63996/in+docs Del: other reasons-- http://master.php.net/note/delete/63996 Reject -- http://master.php.net/note/reject/63996 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107359) next »