Giter Site home page Giter Site logo

uaparser's Introduction

UAParser Build Status

UAParser is a library which helps you to parse user agents and detect browser, operating system, device and more.

SensioLabsInsight

Basic Usage

<?php

// create a new UAParser instance
$uaParser = new \UAParser\UAParser();

// ...or optionally load a custom regexes.yml file of your choice
// $uaParser = new \UAParser\UAParser(__DIR__.'/../../custom_regexes.yml');

// parse a user agent string an get the result
$result =  $uaParser->parse('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/23.0.1');

Results

Global Result API

  • $result->getBrowser() will return a UAParser\Result\BrowserResult object
  • $result->getOperatingSystem() will return a UAParser\Result\OperatingSystemResult object
  • $result->getDevice() will return a UAParser\Result\DeviceResult object
  • $result->getRenderingEngine() will return a UAParser\Result\RenderingEngineResult object
  • $result->getEmailClient() will return a UAParser\Result\EmailClientResult object

Browser

  • $result->getBrowser()->getFamily() will return a string like Firefox
  • $result->getBrowser()->getMajor() will return an integer like 23
  • $result->getBrowser()->getMinor() will return an integer like 0
  • $result->getBrowser()->getPatch() will return an integer like 1
  • $result->getBrowser()->getVersionString() will return a string like 23.0.1

Operating System

  • $result->getOperatingSystem()->getFamily() will return a string like Mac OS
  • $result->getOperatingSystem()->getMajor() will return a string like 10
  • $result->getOperatingSystem()->getMinor() will return a string like 8
  • $result->getOperatingSystem()->getPatch() will return a string like 4

Device

  • $result->getDevice()->getConstructor() will return a string like Apple
  • $result->getDevice()->getModel() will return a string like iPhone
  • $result->getDevice()->getType() will return a string like mobile
  • $result->getDevice()->isMobile() will return a boolean like true
  • $result->getDevice()->isTablet() will return a boolean like false
  • $result->getDevice()->isDesktop() will return a boolean like false
  • $result->getDevice()->is('mobile') will return a boolean like false
  • $result->getDevice()->is('tablet') will return a boolean like false
  • $result->getDevice()->is('desktop') will return a boolean like false

EmailClient

  • $result->getEmailClient()->getFamily() will return a string like Thunderbird
  • $result->getEmailClient()->getMajor() will return a string like 3
  • $result->getEmailClient()->getMinor() will return a string like 1
  • $result->getEmailClient()->getPatch() will return a string like 2
  • $result->getEmailClient()->getType() will return a string like desktop
  • $result->getEmailClient()->isDesktop() will return a boolean like true
  • $result->getEmailClient()->isWebmail() will return a boolean like false
  • $result->getEmailClient()->is('desktop') will return a boolean like true
  • $result->getEmailClient()->is('webmail') will return a boolean like false

Rendering Engine

  • $result->getRenderingEngine()->getFamily() will return a string like Trident
  • $result->getRenderingEngine()->getVersion() will return a string like 4.0

Unit Tests

To run unit tests, you'll need cURL and a set of dependencies you can install using Composer:

curl -sS https://getcomposer.org/installer | php
php composer.phar install

Once installed, just launch the following command:

./vendor/bin/phpunit

You're done.

Credits

Thanks for providing a huge amount of data to run tests:

License

UAParser is released under the MIT License. See the bundled LICENSE file for details.

uaparser's People

Contributors

alecsammon avatar rpeterson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.