Regular expression to detect Internet Explorer 11

后端 未结 8 1936
逝去的感伤
逝去的感伤 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:20

    It's always good to use another character which is not in regexp string so you don't have to escape your string and easier to read for long ones. So you may use ~ for delimiter:

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

    Another idea is to use stristr function to see if a string occurs in another one

    stristr($_SERVER['HTTP_USER_AGENT'],'Trident/7.0; rv:11.0')
    

提交回复
热议问题