RSSAmplifier

Donat Studios · Mar 30, 2011

PHP User Agent Parser

0
Sign in to vote or save

Jesse G. Donat · Donat Studios

Requirements

  • PHP >= 5.4.0

Download

The script is available over on GitHub or via Composer:

$ composer require 'donatj/phpuseragentparser'

Usage

The original procedural use is as simple as:

<?php
// v0 style global function - @deprecated
$uaInfo = parse_user_agent();
// or
// modern namespaced function
$uaInfo = donatj\UserAgent\parse_user_agent();
echo $uaInfo[donatj\UserAgent\PLATFORM] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER_VERSION] . PHP_EOL;

The new object oriented wrapper form:

<?php
use donatj\UserAgent\UserAgentParser;
$parser = new UserAgentParser();
// object-oriented call
$ua = $parser->parse();
// or
// command style invocation
$ua = $parser();
echo $ua->platform() . PHP_EOL;
echo $ua->browser() . PHP_EOL;
echo $ua->browserVersion() . PHP_EOL;

Currently Detected Platforms

see: List of Detected Browsers


Read the original on donatstudios.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.