Home » Php » php – How to find the useragent using the browscap v4

php – How to find the useragent using the browscap v4

Posted by: admin February 25, 2020 Leave a comment

Questions:

Earlier in browsCap v2, the $browscap->getBrowser() used to return an array element ‘browser_name’ which had value as user agent.
In v4, ‘browser_name’ is not returned. How can we find the useragent using new version of browscap

My code

$fileCache = new \Doctrine\Common\Cache\FilesystemCache(BROWSECAP_DIR);
$cache = new \Roave\DoctrineSimpleCache\SimpleCacheAdapter($fileCache);
$logger = new \Monolog\Logger('name');
$browscap = new \BrowscapPHP\Browscap($cache, $logger);
$data = $browscap->getBrowser();

Array returned:

stdClass Object
(
    [browser_name_regex] => /^mozilla\/5\.0 \(.*windows nt 6\.1.*\) applewebkit.* \(.*khtml.*like.*gecko.*\) chrome\/79\.0.*safari\/.*$/
    [browser_name_pattern] => mozilla/5.0 (*windows nt 6.1*) applewebkit* (*khtml*like*gecko*) chrome/79.0*safari/*
    [parent] => Chrome 79.0
    [comment] => Chrome 79.0
    [browser] => Chrome
    [browser_type] => unknown
    [browser_bits] => 0
...
How to&Answers: