Skip to content

Instantly share code, notes, and snippets.

@ifahrentholz
Created May 18, 2016 11:59
Show Gist options
  • Save ifahrentholz/eb8ed47e7d96a3707f01144d0c62aaf3 to your computer and use it in GitHub Desktop.
Save ifahrentholz/eb8ed47e7d96a3707f01144d0c62aaf3 to your computer and use it in GitHub Desktop.
sub plGetDeviceType {
my ($szUAgt) = shift;
if (3 >= length($szUAgt)) { return 0; } # unknown
if ($szUAgt =~ /Windows NT/) { return 1; } # desktop
if ($szUAgt =~ /iPad/ || ($szUAgt =~ /Android/i && $szUAgt !~ /mobile/i) || $szUAgt =~ /tablet/i || $szUAgt =~ /iPod/) {
return 2; # tablet
} elsif (($szUAgt =~ /Android/i && $szUAgt =~ /mobile/i) || $szUAgt =~ /CPU iPhone/ || $szUAgt =~ /mobile safari/i || $szUAgt =~ /Windows Phone/i ||
$szUAgt =~ /Opera Mobi/i) {
return 3; # smartphone
}
return 1; # desktop
}
@ifahrentholz
Copy link
Author

yes. it's perl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment