Are there any best practices for accurately extracting version numbers from user agents in PHP?

When extracting version numbers from user agents in PHP, it's important to use regular expressions to accurately capture the version information. One common approach is to define patterns for different types of user agents and extract the version number based on those patterns. Additionally, using a library like `get_browser()` can simplify the process by providing a standardized way to extract version information from user agents.

$userAgent = $_SERVER['HTTP_USER_AGENT'];

// Define a regular expression pattern to extract version number from a user agent
$pattern = '/(Version\/\d+\.\d+|Chrome\/\d+\.\d+|Firefox\/\d+\.\d+)/';

if (preg_match($pattern, $userAgent, $matches)) {
    $version = explode('/', $matches[0])[1];
    echo "Version number: " . $version;
} else {
    echo "Version number not found";
}