What are available solutions of a browser / mobile phone detection

后端 未结 3 857
逝去的感伤
逝去的感伤 2020-12-05 05:59

I am creating a phonegap application for various mobile platforms and I was wondering what is a current best solution of browser/mobile phone detection?

Should I go

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 06:29

    I've code something like this to get the device os type... the $test will be the string of the user agent

       if (preg_match("/linux/i", $test) && preg_match("/android/i", $test)) {
            $device_type = 'Android';
        } else if (preg_match("/windows phone/i", $test)){
            $device_type = 'Windows Mobile';
        } else if (preg_match("/windows nt/i", $test)){
            $device_type = 'Windows';
        } else if (preg_match("/linux/i", $test)){
            $device_type = 'Linux';
        } else if (preg_match("/macintosh/i", $test)){
            $device_type = 'Macintosh';
        } else if (preg_match("/iphone/i", $test)){
            $device_type = 'iPhone';
        } else if (preg_match("/ipad/i", $test)){
            $device_type = 'iPad';
        }  else if (preg_match("/symbian/i", $test)){
            $device_type = 'Symbian';
        } else if (preg_match("/blackberry/i", $test)){
            $device_type = 'Blackberry';
        } else
            $device_type = 'None';
    

    I think you need to know the pattern and get the keyword. Using WURFL sometimes doesnt get what you want.

提交回复
热议问题