|
| 1 | +[](https://travis-ci.org/VIPnytt/UserAgentParser) |
| 2 | +[](https://scrutinizer-ci.com/g/VIPnytt/UserAgentParser/?branch=master) |
| 3 | +[](https://codeclimate.com/github/VIPnytt/UserAgentParser) |
| 4 | +[](https://codeclimate.com/github/VIPnytt/UserAgentParser/coverage) |
| 5 | +[](https://github.com/VIPnytt/UserAgentParser/blob/master/LICENSE) |
| 6 | +[](https://packagist.org/packages/vipnytt/useragentparser) |
| 7 | +[](https://gitter.im/VIPnytt/UserAgentParser) |
| 8 | + |
| 9 | +# User-Agent string parser class |
| 10 | +PHP class to parse User-Agent strings. |
| 11 | + |
| 12 | +[](https://insight.sensiolabs.com/projects/1386c14c-546c-4c42-ac55-91ea3a3a1ae1) |
| 13 | + |
| 14 | +## Installation |
| 15 | +The library is available for install via [Composer](https://getcomposer.org). Just add this to your `composer.json` file: |
| 16 | +```json |
| 17 | +{ |
| 18 | + "require": { |
| 19 | + "vipnytt/useragentparser": "0.1.*" |
| 20 | + } |
| 21 | +} |
| 22 | +``` |
| 23 | +Then run `composer update`. |
| 24 | + |
| 25 | +## Features |
| 26 | +- Strip the version tag. |
| 27 | +- Find different groups the User-Agent belongs to. |
| 28 | +- Determine the correct group of records by finding the group with the most specific user-agent that still matches. |
| 29 | + |
| 30 | +## When do I need it? |
| 31 | +- Parsing of `robots.txt`, the rules for robots online. |
| 32 | +- Parsing of the _X-Robots-Tag_ HTTP-header. |
| 33 | +- Parsing of _Robots meta tags_ in HTML documents |
| 34 | + |
| 35 | + |
| 36 | +## Getting Started |
| 37 | + |
| 38 | +### Strip the version tag. |
| 39 | +```php |
| 40 | +use vipnytt\UserAgentParser; |
| 41 | + |
| 42 | +$parser = new UserAgentParser('googlebot/2.1'); |
| 43 | +var_dump($parser->stripVersion()); |
| 44 | +/* googlebot */ |
| 45 | +``` |
| 46 | + |
| 47 | +### Find different groups the User-Agent belongs to. |
| 48 | +```php |
| 49 | +use vipnytt\UserAgentParser; |
| 50 | + |
| 51 | +$parser = new UserAgentParser('googlebot-news/2.1'); |
| 52 | +var_dump($parser->export()); |
| 53 | +/* |
| 54 | + * googlebot-news/2.1 |
| 55 | + * googlebot-news |
| 56 | + * googlebot |
| 57 | + */ |
| 58 | +``` |
| 59 | + |
| 60 | +### Determine the correct group |
| 61 | +Determine the correct group of records by finding the group with the most specific user-agent that still matches. |
| 62 | +```php |
| 63 | +use vipnytt\UserAgentParser; |
| 64 | + |
| 65 | +$parser = new UserAgentParser('googlebot-news'); |
| 66 | +var_dump($parser->match(['googlebot/2.1', 'googlebot-images','googlebot'])); |
| 67 | +/* googlebot */ |
| 68 | +``` |
0 commit comments