Posted on: 03/11/06 07:47pm
By: sakata
Hi,
I've written function which split text length to certain length.
In Japanese, the default function cuts text strange place.
Solving this problem, we should use mb_ functions.
If it works non-mb_ function support environment, I propose to include this function to lib-common.php and use it when we should split text.
This function has the following feature.
1) detect mb_ function support
2) split text for certain length
3) add '...' to the last
function COM_titlesplit($itemtext, $maxlen="10")
{
if (!function_exists('mb_substr'))
{
$itemlen = strlen($itemtext);
if ($itemlen > $maxlen)
{
$itemtext = substr( $titletext, 0, $maxlen) . '...';
}
}
else
{
$itemlen = mb_strlen($itemtext, mb_detect_encoding($itemtext) );
if ($itemlen > $maxlen)
{
$itemtext = mb_substr( $titletext, 0, $maxlen , mb_detect_encoding($itemtext)) . '...';
}
}
return $itemtext;
}
Adding title split functions for multi-byte language
Posted on: 03/12/06 03:55am
By: Dirk
Sorry, forgot to notify you: It already made it
into CVS[*1] , under the name COM_truncate.
bye, Dirk
Adding title split functions for multi-byte language
Posted on: 03/12/06 07:00am
By: sakata
That's great.
Thanks.
I hope developers use this function for multi-byte users.