rilwanfit / yauaa-php
Yet Another User Agent Analyzer โ a PHP implementation
v1.1.0
2025-05-05 19:19 UTC
Requires
- php: ^8.0
- symfony/yaml: ^7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpunit/phpunit: ^10
README
Yet Another User Agent Analyzer โ PHP Edition
A lightweight and extensible PHP library for parsing and analyzing User-Agent strings, inspired by the original YAUAA (Java).
๐ Special Thanks
This project is heavily inspired by the amazing work of Niels Basjes, author of the original Yet Another UserAgent Analyzer (YAUAA).
Without YAUAA, this PHP version wouldn't exist.
๐ Features
- Detect browser (agent) name and version
- Detect layout engine [ToDo]
- Detect operating system and version [ToDo]
- Detect device class, brand, and name
- Basic bot detection support
- Pattern-driven and fully customizable (via YAML)
- No external dependencies required (except Symfony YAML parser)
๐งฐ Installation
composer require rilwanfit/yauaa-php
๐งช Example Usage
use Rilwanfit\YauaaPhp\Analyzer; $analyzer = new Analyzer(__DIR__ . '/resources/patterns.yaml'); $result = $analyzer->analyze('Mozilla/5.0 Chrome/117.0.0.0 Safari/537.36'); print_r($result); if ($analyzer->isMobile()) { echo "This is a mobile device."; } echo "Device class: " . $analyzer->getDeviceClass(); echo "Agent type: " . $analyzer->getAgentType();
๐ฆ Custom Patterns
Patterns are loaded from a YAML file (resources/patterns.yaml
). Example format:
browsers: - name: "Chrome" class: "Browser" pattern: "~Chrome/(?<version>[\\d\\.]+)~i" os: - name: "Windows" class: "Operating System" pattern: "~Windows NT (?<version>[\\d\\.]+)~i" device: - name: "Desktop" class: "Desktop" pattern: "~Windows NT~i"
โ Testing
composer install ./vendor/bin/phpunit
๐งฑ Directory Structure
src/
Analyzer.php
resources/
patterns.yaml
tests/
AnalyzerTest.php
๐ License
This project is licensed under the MIT License.
๐จโ๐ป Author
Built by Rilwan Fit