uap-php
A PHP port of Browserscope's user-agent parser for extracting browser, OS, and device details from UA strings.
Repository Health
Technical Analysis
ua-parser/uap-php is the PHP implementation of the ua-parser project, a multi-language port of Browserscope’s user-agent parser. It takes a raw user-agent string and returns structured information about the browser, operating system, and device, including family names and version components.
Parsing is driven by the shared uap-core regex database, so PHP applications get the same battle-tested detection rules used across the ua-parser ecosystem. It ships with a simple Parser API plus a command-line utility for updating and converting the regex file.
What You Get
- A Parser::create() factory and parse() method returning structured browser, OS, and device data
- Result objects with family, version parts, and toString()/toVersion() helpers
- Detection powered by the shared, community-maintained uap-core regex database
- A bin/uaparser CLI for updating and converting the regexes file
- Support for supplying your own custom regexes.php file
Common Use Cases
- Detecting the browser and OS of visitors from request user-agent headers
- Segmenting analytics or logs by device family and platform
- Tailoring responses or feature availability based on the client device
- Keeping detection rules current via scheduled CLI updates of the regex file
Under The Hood
Architecture - The library is organized under the UAParser\ PSR-4 namespace. A Parser (extending AbstractParser) delegates to UserAgentParser, OperatingSystemParser, and DeviceParser, each matching the UA string against patterns loaded from the uap-core regexes.php resource. Results are assembled into Result value objects (UserAgent, OperatingSystem, Device). ParserFactoryMethods supplies the create() entry point, and a Command namespace implements the CLI.
Tech Stack - PHP ^7.2 || ^8.0, requiring composer/ca-bundle. Optional Symfony components (yaml, filesystem, finder, console) power the CLI. Testing and static analysis use PHPUnit, PHPStan, and Psalm.
Code Quality - The codebase separates concerns cleanly across dedicated parser and result classes, ships a tests directory run under PHPUnit, and includes psalm.xml and PHPStan config for static analysis, indicating attention to type safety and correctness.
API Design - The public API is minimal and ergonomic: create a parser, call parse(), and read strongly-shaped result fields. The optional custom-regexes path and CLI update command make maintenance straightforward without complicating the common case.