What are some best practices for efficiently counting and extracting information from user-agent strings in PHP?

When working with user-agent strings in PHP, it is important to efficiently count and extract information from them. One best practice is to use regular expressions to parse the user-agent string and extract the desired information. Additionally, you can use the `get_browser()` function in PHP to get detailed information about the user's browser.

$userAgent = $_SERVER['HTTP_USER_AGENT'];

// Extracting browser information using regular expressions
if (preg_match('/MSIE/i', $userAgent)) {
    echo 'Internet Explorer';
} elseif (preg_match('/Firefox/i', $userAgent)) {
    echo 'Mozilla Firefox';
} elseif (preg_match('/Chrome/i', $userAgent)) {
    echo 'Google Chrome';
} elseif (preg_match('/Safari/i', $userAgent)) {
    echo 'Apple Safari';
} elseif (preg_match('/Opera/i', $userAgent)) {
    echo 'Opera';
}

// Using get_browser() function to get detailed browser information
$browserInfo = get_browser(null, true);
echo $browserInfo['browser'] . ' ' . $browserInfo['version'];