LoginSignup
1
1

More than 5 years have passed since last update.

文字エンコーディング(UTF-8 <--> SJIS)

Posted at

もっといい方法があるのかもしれませんが、よく使うので作ってみました。
mb_convert_encoding で引数を指定するのが面倒くさいと思ったためです。

<?php //encoder.php
/*
utf8とsjisエンコーディングの橋渡しをするクラスです。

使い方

utf8からsjisへエンコーディングをするとき
    $result = Encoder::sjis($string)

sjisからutf8へエンコーディングをするとき
    $result = Encoder::utf8($string)
*/
class Encoder{
    const utf8 = 'utf-8';
    const sjis = 'sjis';

    public static function sjis($string){
        return mb_convert_encoding($string, self::sjis, self::utf8);
    }
    public static function utf8($string){
        return mb_convert_encoding($string, self::utf8, self::sjis);
    }
}
?>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1