note 75406 added to function.str-word-count

From: Date: Mon, 28 May 2007 11:52:06 +0000
Subject: note 75406 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-126979@lists.php.net to get a copy of this message
Here's a very fast word limiter function that preserves the original whitespace. <?php function word_limiter($str, $limit = 100, $end_char = '&#8230;') { if (trim($str) == '') return $str; preg_match('/\s*(?:\S*\s*){'. (int) $limit .'}/', $str, $matches); if (strlen($matches[0]) == strlen($str)) $end_char = ''; return rtrim($matches[0]) . $end_char; } ?> For the thought process behind this function, please read: http://codeigniter.com/forums/viewthread/51788/ Geert De Deckere ---- Server IP: 193.190.198.20 Probable Submitter: 83.101.9.26 ---- Manual Page -- http://www.php.net/manual/en/function.str-word-count.php Edit -- https://master.php.net/note/edit/75406 Del: integrated -- https://master.php.net/note/delete/75406/integrated Del: useless -- https://master.php.net/note/delete/75406/useless Del: bad code -- https://master.php.net/note/delete/75406/bad+code Del: spam -- https://master.php.net/note/delete/75406/spam Del: non-english -- https://master.php.net/note/delete/75406/non-english Del: in docs -- https://master.php.net/note/delete/75406/in+docs Del: other reasons-- https://master.php.net/note/delete/75406 Reject -- https://master.php.net/note/reject/75406 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126979) next »