Regular expression to detect Internet Explorer 11

后端 未结 8 1828
逝去的感伤
逝去的感伤 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条回答
  • 2021-01-11 19:43

    I think it should be

    if (preg_match("/Trident\/7.0;(.*)rv:11.0/", $_SERVER["HTTP_USER_AGENT"], $match) != 0) {}
    

    because sometimes you can see the user agent like this one

    Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; ASU2JS; rv:11.0) like Gecko

    0 讨论(0)
  • 2021-01-11 19:46

    The / after Trident is being treated as a delimiter. You could escape it:

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

    Better, however, would be not to use preg_match: you don't need it. All you're doing is looking for an invariant substring, which can be done with strpos:

    if (false !== strpos($_SERVER["HTTP_USER_AGENT"], '/Trident/7.0; rv:11.0/')) {
    
    0 讨论(0)
提交回复
热议问题