LoginSignup
13
12

More than 5 years have passed since last update.

【PHP】機種依存文字を変換する最低限のコード

Posted at

やりたかったこと

ローマ数字や(株)などの機種依存文字を、大抵の環境で見られる文字に変換する必要が合った。

コード

    function convSpecialChar($subject) {

        //変換前の文字
        $search = Array('Ⅰ','Ⅱ','Ⅲ','Ⅳ','Ⅴ','Ⅵ','Ⅶ','Ⅷ','Ⅸ','Ⅹ','①','②','③','④','⑤','⑥','⑦','⑧','⑨','⑩','№','㈲','㈱');
        //変換後の文字
        $replace = Array('I','II','III','IV','V','VI','VII','VIII','IX','X','(1)','(2)','(3)','(4)','(5)','(6)','(7)','(8)','(9)','(10)','No.','(有)','(株)');

        $ret = str_replace($search, $replace, $subject);

        return $ret;
    }

これで何とかなりました。
よく使われる文字だけの変換なので、全ての文字は網羅していません。

参考

13
12
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
13
12