Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 06:16 am EDT

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;
}

 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Sorry, forgot to notify you: It already made it into CVS, under the name COM_truncate.

bye, Dirk
 Quote

Status: offline

sakata

Forum User
Junior
Registered: 12/17/01
Posts: 25
Location:Japan
That's great.
Thanks.

I hope developers use this function for multi-byte users.
 Quote

All times are EDT. The time is now 06:16 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