note 95249 added to function.str-word-count
| From: | mark at atlasdesignsolutions dot com | Date: | Mon, 21 Dec 2009 16:10:56 +0000 |
| Subject: | note 95249 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164176@lists.php.net to get a copy of this message | ||
I find this approach to be much more practical than using the word count function, which depending
on the size of your text string, it can be very resource intensive.
Instead of putting all the words in an array, we decide the approximate number of characters we want
(600 in this case) then find the next space in the string and get its numerical location. Then we
splice out the part of the string we want.
Hope this helps someone.
if(strlen($text_string) > 600){
$truncate = strpos($text_string, ' ', 600);
$extrafield_value = substr($extrafield_value, 0, $truncate) . '...';
}
----
Server IP: 69.147.83.197
Probable Submitter: 71.197.38.29
----
Manual Page -- http://www.php.net/manual/en/function.str-word-count.php
Edit -- https://master.php.net/note/edit/95249
Del: integrated -- https://master.php.net/note/delete/95249/integrated
Del: useless -- https://master.php.net/note/delete/95249/useless
Del: bad code -- https://master.php.net/note/delete/95249/bad+code
Del: spam -- https://master.php.net/note/delete/95249/spam
Del: non-english -- https://master.php.net/note/delete/95249/non-english
Del: in docs -- https://master.php.net/note/delete/95249/in+docs
Del: other reasons-- https://master.php.net/note/delete/95249
Reject -- https://master.php.net/note/reject/95249
Search -- https://master.php.net/manage/user-notes.php