PHP implementation of ua-parser
This is the PHP library for the uap-core project.
composer require ua-parser/uap-phpStraightforward:
…You can use your own regexes.php file if you've customized the official file. I strongly encourage you to push back any changes you may have so others can benefit. That said, to use your own do the following:
require_once 'vendor/autoload.php';
use UAParser\Parser;
$parser = Parser::create("path/to/custom/regexes.php");A command line utility is now included with the PHP library. The following commands are supported:
Provides simple usage information:
php bin/uaparserFetches an updated YAML file for ua-parser and overwrites the current regexes.php file. You can use the following as part of a cron job that runs nightly.
php bin/uaparser ua-parser:update [--no-backup]By default creates a backup file. Use --no-backup to turn that feature off.
With the change to v2.0 you may have an existing and customized YAML file for ua-parser. Use the following to convert it to JSON.
php bin/uaparser ua-parser:convert [file]If you need to add a new UA it's easier to edit the original YAML and then convert it to JSON.
php bin/uaparser ua-parser:fetch [file]Fetches an updated YAML file. Warning: This method overwrites any existing regexes.yaml file.
Parses a user agent string and dumps the results as a list.
php bin/uaparser ua-parser:parse "your user agent string"Parses the supplied log file or log directory to test ua-parser. Saves the UA to a file when the UA or OS family aren't recognized or when the UA is listed as a generic smartphone or as a generic feature phone.
php bin/uaparser ua-parser:logfile [-f /path/to/logfile] [-d /path/to/logdir] [--include "*.gz"] [--exclude "*.gz"] errors.logMultiple --include and --exclude parameters are allowed.
Thanks to the original ua-parser team for making the YAML file available for others to build upon.
Also, many thanks to the following major contributors to the PHP library:
No open issues yet, or sync has not completed.