Regular expression to detect Internet Explorer 11

后端 未结 8 1979
逝去的感伤
逝去的感伤 2021-01-11 18:43

I am using this preg_match string

preg_match(\'/Trident/7.0; rv:11.0/\',$_SERVER[\"HTTP_USER_AGENT\"]

to detect IE11 so I can

8条回答
  •  猫巷女王i
    2021-01-11 19:26

    IE11 has touch versions and non-touch versions, this means that the Guilherme Sehn's answer will not work for touch devices.

    if(strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)
    

    Instead, use this:

    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'rv:11.0')     !== false
      && strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;')!== false)
    {
        echo "User is on IE11 touch / non-touch";
    }
    

    This is because any number of parameters could be added between "Trident" and the revision number.

    Likewise if you want to check if they're on touch just do a strpos for "Touch;".

提交回复
热议问题