When working with Smarty, a PHP templating engine, I discovered that while the regular truncate
modifier works great on ASCII strings, it doesn’t work with multibyte strings, i.e. UTF-8 encoded strings. This leads to problems in internationalization (i18n), as UTF-8 is the popular encoding for non-Latin alphabets nowdays. The problem can be solved by modifying the built-in truncate
modifier and create a new one that takes an additional argument, the charset of the string, and acts accordingly. The new modified modifier, mb_truncate
is implemented below.
Continue reading Multibyte String Truncate Modifier for Smarty – mb_truncate