PHP User Agent Parser

Lightning-fast, minimalist PHP parser that turns User-Agent strings into browser and platform.

Library
Composer
vv1.12.0
595stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity72
Maintenance68
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture78
Code Quality82
Innovation70
Learning Curve90

PhpUserAgent (donatj/phpuseragentparser) is a lightning-fast, minimalist PHP library for parsing HTTP User-Agent strings into their key components: browser name, browser version, and platform. It deliberately avoids the enormous rule databases used by heavier device-detection tools, favoring a compact regular-expression approach that stays fast and dependency-free.

The library exposes a single parse function (and an object-oriented wrapper) that returns a structured result from any User-Agent string. It is a long-standing, well-maintained option for lightweight browser and platform detection in PHP applications, analytics pipelines, and logging, where knowing the broad browser/OS is enough and full device fingerprinting is unnecessary.

What You Get

  • A simple parse_user_agent() function returning browser, version, and platform
  • An object-oriented UserAgent wrapper for typed access
  • No runtime dependencies beyond ext-ctype and no external data files
  • Broad PHP compatibility (PHP 5.4 through modern versions)
  • Fast, allocation-light parsing suited to high-throughput logging

Common Use Cases

  • Recording browser and platform for server-side analytics
  • Enriching access logs with human-readable client information
  • Lightweight browser gating without a full device-detection database
  • Segmenting traffic by browser or OS in reporting pipelines

Under The Hood

Architecture - The core is src/UserAgentParser.php, which exposes the procedural parse_user_agent() function that applies a single large, carefully ordered regular expression to extract platform, browser, and version tokens from the User-Agent string. An object-oriented layer under src/UserAgent (donatj\UserAgent namespace) wraps the array result in a UserAgent value object with typed getters.

Tech Stack - Pure PHP with an extremely small dependency surface — only the ctype extension is required at runtime, and no external device databases are bundled. Composer autoloads both the function file and the PSR-4 namespace. Development uses PHPUnit and a Makefile-driven workflow.

Code Quality - Despite its age, the project is actively maintained with 50+ releases, a focused tests/ suite, and continuous refinement of its regex against real-world User-Agent samples. The minimalist design keeps the surface small and auditable.

API Design - The API is intentionally tiny: call parse_user_agent($ua) for an associative array, or instantiate UserAgent for typed access. There are no configuration steps, data downloads, or setup, which makes it trivial to drop into an existing codebase.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search