PEAK XOOPS - Re: backend.php & EMLH in englishin japanese

Re: backend.php & EMLH

List posts in the topic

question Re: backend.php & EMLH

msg# 1.1.1.1.1.1.1.1.1.1.1.1.1.1.1
depth:
14
Previous post - Next post | Parent - Children.1 | Posted on 2005/4/16 5:51
GIJOE  ÀèǤ·³Áâ   Posts: 4110
hi Yuji.

OK.
I've just understand what you mean.

truncate is just a substr();
substr() can't be used in multibyte language like Japanese.

You should make mbtruncate like this:

class/smarty/plug-ins/modifier.mbtruncate.php
<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     modifier
 * Name:     mbtruncate
 * Purpose:  Truncate a string to a certain length if necessary,
 *           optionally splitting in the middle of a word, and 
 *           appending the $etc string.
 * -------------------------------------------------------------
 */
function smarty_modifier_mbtruncate($string, $length = 80, $etc = '...',
                                  $break_words = false)
{
    if ($length == 0)
        return '';

    if (strlen($string) > $length) {
        $length -= strlen($etc);	
        if (!$break_words)
	    $string = preg_replace('/\s+?(\S+)?$/', '', mb_strcut($string, 0, $length+1));
      
        return mb_strcut($string, 0, $length).$etc;
    } else
        return $string;
}
?>

Of course, mbstring should be installed.


But, both cutting-in-template(mbtruncate) and cutting-in-php might harm EMLH, I think.

Votes:0 Average:0.00

Posts tree

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!