Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 07:27 am EST
Geeklog Forums
Adding title split functions for multi-byte language
Status: offline
sakata
Forum User
Junior
Registered: 12/17/01
Posts: 25
Location:Japan
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;
}
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;
}
13
8
Quote
All times are EST. The time is now 07:27 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content