note 95249 deleted from function.str-word-count by danbrown
| From: | danbrown@php.net | Date: | Mon, 21 Dec 2009 16:59:23 +0000 |
| Subject: | note 95249 deleted from function.str-word-count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164179@lists.php.net to get a copy of this message | ||
Note Submitter: mark at atlasdesignsolutions dot com
----
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) . '...';
}