EEフォーラム

UTF-8 から Shift-JIS への変更

 
合計ポスト数: 1

携帯HPに Shift-JIS コンテンツを出さなきゃが、UTF-8 をデータベースに使いたかって、iconv 使っとるプラグインを作りました。同じコンテンツの携帯HP、そしてパソコンHPを出す時、皆はなにするのか?

I want to use UTF-8 for the database (and main homepage), but output in Shift-JIS for a keitai site, so I made an iconv-based plugin. What do you do when producing a keitai site and a normal site using the same content?

I’m no programmer but here’s the plugin code, in case it’s of use to someone:

class Iconvify
{
    
var $return_data "";
    function 
Iconvify() {
        
// Setup
        
global $TMPL;
        
$string $TMPL->tagdata;
        
$from = ( ! $TMPL->fetch_param('from')) ? 'utf-8' $TMPL->fetch_param('from');
        
$to = ( ! $TMPL->fetch_param('to')) ? 'shift-jis' $TMPL->fetch_param('to');
        
// Convert
        
if ($from == 'utf-8' && $to == 'shift-jis')
        
{
            
// Fix tildes for Shift-JIS
            
$replaced preg_replace ('/~/','1bytetilde',$string);   //replace tilde before conversion
            
$converted iconv($from,$to.'//TRANSLIT',$replaced); //convert replaced string
            
$tilde=chr(126); //$tilde equals a one byte shift_jis tilde
            
$this->return_data preg_replace ('/1bytetilde/',$tilde,$converted);  //add tildes back in
        
}
        
else
        
{
            
// just convert
            
$this->return_data iconv($from,$to.'//TRANSLIT',$string); //convert string
        
}
    }
}

Any feedback would be appreciated (first plugin and all)

peace - oli