Guy Rutenberg

Keeping track of what I do

Archive for the ‘Smarty’ tag

Multibyte String Truncate Modifier for Smarty – mb_truncate

with 14 comments

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.
Read the rest of this entry »

Written by Guy

December 4th, 2007 at 3:53 pm

Posted in PHP

Tagged with