How can I just display the browser name and version only no extra information using' HTTP_USER_AGENT'?


how can I alter my script so that just the browser version and name is only displayed using’ HTTP_USER_AGENT’? I still need my script to cover all modern browsers just incase someone helps me and specifies the code only for the safari browser.

In my code the current output is “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15” just to make it cleat I’m on looking for this to be display “BROWSER NAME + BROWSER VERSION”.

Any tutorial links as well would be greatly appreciated.

<!DOCTYPE html>

$browser = get_browser();

I also tried this as well below.

$browser = get_browser($_SERVER['HTTP_USER_AGENT'], true);
echo $browser['browser'] . '+' . $browser['version'];



According to users comments on the manual, browser detection can be tricky and very slow, so you should use a library or user-agent-parser for this purpose. It’s also a lot faster to use a good library. Some suggested these
For speed:

For efficiency: