Posted By

sherakama on 11/20/10


Tagged

get php textmate system os operating


Versions (?)

Get Operating System


 / Published in: PHP
 

  1. // returns a class based on the OS
  2. function get_os() {
  3. $oses = array(
  4. 'Win' => 'Win16',
  5. 'Win' => '(Windows 95)|(Win95)|(Windows_95)',
  6. 'Win' => '(Windows 98)|(Win 9x 4.90)|(Windows ME)',
  7. 'Win' => '(Windows 98)|(Win98)',
  8. 'Win' => '(Windows NT 5.0)|(Windows 2000)',
  9. 'Win' => '(Windows NT 5.1)|(Windows XP)',
  10. 'Win' => '(Windows NT 5.2)',
  11. 'Win' => '(Windows NT 6.0)',
  12. 'Win' => '(Windows NT 6.1)',
  13. 'Win' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
  14. 'OpenBSD' => 'OpenBSD',
  15. 'SunOS' => 'SunOS',
  16. 'Linux' => '(Linux)|(X11)',
  17. 'MacOS' => '(Mac_PowerPC)|(Macintosh)',
  18. 'QNX' => 'QNX',
  19. 'BeOS' => 'BeOS',
  20. 'OS2' => 'OS/2',
  21. 'SearchBot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
  22. );
  23.  
  24. $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
  25. foreach($oses as $os=>$pattern) {
  26. if (preg_match('/'.$pattern.'/i', $agent)) {
  27. return " ".$os;
  28. }
  29. }
  30. return "";
  31. }

Report this snippet  

You need to login to post a comment.