CodeClerks

android get version from user agent in php

android get version from user agent in php

I just need a working code that gets the Android API version (and if possible the version number like 10.0.0)

So API version like 28 or 29

AND/OR

The Android version such as Android pie veriosn 9 or version 8

Only need the first number from the version code which is like 9.0.1

I have tried code like this:

else
 {
 $txt = $_SERVER['HTTP_USER_AGENT'];$ANDROIDAPI="0";
 if (strpos($txt,"Android")!=false)
  {
  $reg = '/Android (\d+)\.(\d+)/';$a = array();    
  preg_match($reg, $txt, $a);
  if (ctype_digit($a[1])) $ANDROIDAPI = $a[1];
  }
 }
$ANDROIDAPI=intval($ANDROIDAPI);


but I get error in php:
[13-Dec-2019 06:36:39 UTC] PHP Notice: Undefined offset: 1 in /home/site/public_html/php/phpscript.php on line 16


Requirements

php coding


Skills Required

Android Php

Bids

No bids made yet - be the first!

Bid On Listing

Bid On Listing Created 5 years ago in PHP

Other jobs by TheRealRio