ExpressionEngine addons

NB moji limit

Description

Similar to the character limiter plugin, but for multibyte characters saved as entities in the database.

Has this ever happened to you?

You have some text in a language that uses multibyte characters (for example, Japanese), but using word/character trimming plugins give you garbled text, especially near the last character. Your foreign characters are probably saved in the database as ASCII entities, and those characters are being trimmed instead.

The NB moji limit plugin allows you to trim foreign language characters correctly, without garbled text (known as mojibake in Japanese).

Usage

{exp:nb_moji_limit limit="10"}
あいうえおかきくけこさしすせそ
{/exp:nb_moji_limit}

...will give

あいうえおかきくけこ...

Parameters

limit="10"

Limits the number of multibyte characters (eg. 10 kana/kanji characters). Default is 50 characters.

encoding="SJIS"

Sets the character encoding. Default is UTF-8.

tail="---"

Adds characters at the end of the truncated string. Default is "..." (non-multibyte). Set to tail="" to add nothing to the end of the string.

Installation

Copy the pi.nb_moji_limit.php file in your /plugins folder.

For ExpressionEngine 2:

Copy the nb_moji_limit folder to your /system/expressionengine/third_party folder.

Important note

This addon uses multibyte capabilities of PHP, namely mb_strlen and mb_substr functions. Make sure these functions are available on your installation of PHP, or the addon may not work as it should.

Changelog

0.1 (EE 1.6.x)

  • First release

2.0 (EE 2.x)

  • Converted for ExpressionEngine 2
Creative Commons License