close

今天在翻某個第三方套件的 Source Code 的時候發現這個常數,可以用來判斷目前執行的作業系統。
在 Windows 7 及 CentOS 測試分別得到 'WINNT' 及 'Linux'

稍微 Google 了一下發現它可能會有以下的值:

  1. CYGWIN_NT-5.1
  2. Darwin
  3. FreeBSD
  4. HP-UX
  5. IRIX64
  6. Linux
  7. NetBSD
  8. OpenBSD
  9. SunOS
  10. Unix
  11. WIN32
  12. WINNT
  13. Windows
  14. CYGWIN_NT-5.1
  15. IRIX64
  16. SunOS
  17. HP-UX
  18. OpenBSD (not in Wikipedia)


如果要用在判斷是否為 Windows 上可以這樣寫

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') 
{
    echo 'This is a server using Windows!';
}
else 
{
    echo 'This is a server not using Windows!';
}

 

arrow
arrow
    全站熱搜

    wbkuo 發表在 痞客邦 留言(0) 人氣()