DEV Community

Cover image for How to Detect Browser in PHP

How to Detect Browser in PHP

Carlos Alberto on January 22, 2021

We will to write a function in PHP using $_SERVER['HTTP_USER_AGENT'] to detect the browser an d SO of the client function detect() { $br...
Collapse
 
lito profile image
Lito

You should escape . on version check expression:

$version = preg_replace('/[^0-9,\.]/', '', $version);
Enter fullscreen mode Exit fullscreen mode