Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

modifier 'replace' with a charset/encoding parameter

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
sskaje
Smarty Rookie


Joined: 12 Nov 2010
Posts: 9

PostPosted: Wed May 11, 2011 4:15 am    Post subject: modifier 'replace' with a charset/encoding parameter Reply with quote

I have an output in smarty like
Code:

PHP:
$smarty->assign('output', 'hello, 测试');
Smarty:
{#$output|replace:'测试':''#}


the output is 'hello, 测试' unless i called mb_regex_encoding('UTF-8'); in PHP, coz its replaced by mb_split() and an implode().

This is not referred in Smarty Documentation。

A third parameter is requested in smarty_modifier_replace.

Code:

function smarty_modifier_replace($string, $search, $replace, $encoding=null)
{
    require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
    if (empty($encoding)) {
        return smarty_mb_str_replace($search, $replace, $string);
    } else {
        $old_encoding = mb_regex_encoding();
        mb_regex_encoding($encoding);
        $ret = smarty_mb_str_replace($search, $replace, $string);
        mb_regex_encoding($old_encoding);
        return $ret;
    }
}
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Wed May 11, 2011 8:43 am    Post subject: Reply with quote

To be consistent every single modifier would have to receive two new paramters (input/output encoding). Doesn't make things simpler…

Therefore we introduced two new modifiers to Smarty 3.1. to_charset and from_charset so you can do any transcoding you need.

Smarty 3.1 has also been made fully UTF-8 compatible. Meaning if SMARTY_RESOURCE_CHAR_SET is set to "UTF-8" and MBString is available, we'll take it from there.

Chances are we'll be releasing Smarty 3.1RC1 within the next few weeks. If you can't wait, you should be able to clone the plugins_dir from http://code.google.com/p/smarty-php/source/browse/branches/rodneyrehm/distribution without too much hassle. Afair you just need to pop in
Code:
if (!defined('SMARTY_MBSTRING')) {
   define('SMARTY_MBSTRING', function_exists('mb_strlen'));
}
somewhere, to make the changed plugins work.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP