note 90246 deleted from function.utf8-decode by danbrown
| From: | danbrown@php.net | Date: | Sun, 12 Apr 2009 15:37:19 +0000 |
| Subject: | note 90246 deleted from function.utf8-decode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153118@lists.php.net to get a copy of this message | ||
Note Submitter: Casper Pascal
----
I've found a solution for cutting an article's summary to make preview text which contains
'utf-8' unicode, without broken words. I hope this might help.
function prevText($str, $limit){
$result = "";
$str = trim($str);
if (mb_strlen($str,'utf-8') <= $limit)
return $str.'...';
$words = explode(' ',$str);
$i = 0;
while (mb_strlen($result.$words[$i],'utf-8') <= $limit){
$result .= $words[$i].' ';
$i++;
}
return trim($result).'...';
}