errorcode418/php
0
1# ua-parser PHP Library #2 3[](https://gitter.im/ua-parser/uap-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://travis-ci.org/ua-parser/uap-php) [](http://isitmaintained.com/project/ua-parser/uap-php "Average time to resolve an issue") [](http://isitmaintained.com/project/ua-parser/uap-php "Percentage of issues still open")4[](https://packagist.org/packages/ua-parser/uap-php)5[](https://packagist.org/packages/ua-parser/uap-php)6[](https://packagist.org/packages/ua-parser/uap-php)7 8This is the PHP library for the [uap-core](https://github.com/ua-parser/uap-core) project.9 10## Installation ##11Add `ua-parser/uap-php` to the require section of your `composer.json` file and run `composer update`.12 13## Usage ##14 15Straightforward:16 17```php18require_once 'vendor/autoload.php';19use UAParser\Parser;20 21$ua = "Mozilla/5.0 (Macintosh; Intel Ma...";22 23$parser = Parser::create();24$result = $parser->parse($ua);25 26print $result->ua->family; // Safari27print $result->ua->major; // 628print $result->ua->minor; // 029print $result->ua->patch; // 230print $result->ua->toString(); // Safari 6.0.231print $result->ua->toVersion(); // 6.0.232 33print $result->os->family; // Mac OS X34print $result->os->major; // 1035print $result->os->minor; // 736print $result->os->patch; // 537print $result->os->patchMinor; // [null]38print $result->os->toString(); // Mac OS X 10.7.539print $result->os->toVersion(); // 10.7.540 41print $result->device->family; // Other42 43print $result->toString(); // Safari 6.0.2/Mac OS X 10.7.544print $result->originalUserAgent; // Mozilla/5.0 (Macintosh; Intel Ma...45```46 47## Using Your Own Custom regexes.php File ##48 49You 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:50 51```php52require_once 'vendor/autoload.php';53use UAParser\Parser;54 55$parser = Parser::create("path/to/custom/regexes.php");56```57 58## Using ua-parser PHP Library from the Command Line ##59 60A command line utility is now included with the PHP library. The following commands are supported:61 62### Get Usage Info63 64Provides simple usage information:65 66 php bin/uaparser67 68### Update the regexes.php File69 70Fetches 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.71 72 php bin/uaparser ua-parser:update [--no-backup]73 74By default creates a backup file. Use `--no-backup` to turn that feature off.75 76### Convert an Existing regexes.yaml File to regexes.php77 78With 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.79 80 php bin/uaparser ua-parser:convert [file]81 82### Grab Just the Latest regexes.yaml File From the Repository83 84If you need to add a new UA it's easier to edit the original YAML and then convert it to JSON.85 86 php bin/uaparser ua-parser:fetch [file]87 88Fetches an updated YAML file. *Warning:* This method overwrites any existing `regexes.yaml` file.89 90### Parse a Single User Agent String91 92Parses a user agent string and dumps the results as a list.93 94 php bin/uaparser ua-parser:parse "your user agent string"95 96### Parse a Webserver Log File97 98Parses 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.99 100 php bin/uaparser ua-parser:logfile [-f /path/to/logfile] [-d /path/to/logdir] [--include "*.gz"] [--exclude "*.gz"] errors.log101 102Multiple `--include` and `--exclude` parameters are allowed.103 104## Credits ##105 106Thanks to the [original ua-parser team](http://code.google.com/p/ua-parser/people/list) for making the YAML file available for others to build upon.107 108Also, many thanks to the following major contributors to the PHP library:109 110* Bryan Shelton111* Michael Bond112* @rjd22113* Timo Tijhof114* Marcus Bointon115* Ryan Parman116* Pravin Dahal117 118## Licensing ##119* The library is licensed under the MIT license120* The user agents data from the ua-parser project is licensed under the Apache license121* The initial list of generic feature phones & smartphones came from Mobile Web OSP under the MIT license122* The initial list of spiders was taken from Yiibu's profile project under the MIT license.123 124 