LoginSignup
3
4

More than 5 years have passed since last update.

PHPでWindowsを区別する方法

Last updated at Posted at 2015-09-29

概要

日本語でファイル名を保存する時に、WindowsとLinuxで文字コードを切り替える処理が必要だったので調べました。

判別方法

その1

function isWindows(){
    $result = (substr(PHP_OS,0,3) == 'WIN');
    return $result;
}

その2

function isWindows() {
    return PHP_OS === 'WIN32' || PHP_OS === 'WINNT';
}

その3

function isWindows(){
    return defined('PHP_WINDOWS_VERSION_MAJOR');
}

文字コードの変換

if ($this->isWindows()) {

    // windowのファイル名(sjis)を、utf-8に変換する
    $fname = mb_convert_encoding($fname, 'utf-8', 'sjis-win');
}
3
4
6

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
3
4