PHP User Agent Parser
Lightning-fast, minimalist PHP parser that turns User-Agent strings into browser and platform.
Repository Health
Technical Analysis
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.
Used by 2 apps in this directory
Passbolt API
Password Manager · Security
Self-hosted, end-to-end encrypted password manager API built for teams who demand full ownership of their credentials.
Shlink
Developer Tools · Marketing
Self-hosted PHP URL shortener with a full REST API, dynamic redirect rules, and real-time visit analytics under your own domain.