Mobile regexp user agent

前端 未结 2 904
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 09:35

i have to check in my script for user agent for mobile.

i have

if(preg_match(\'/lg|iphone|blackberry|opera/i\', $_SERVER[\'HTTP_USER_AGENT\'])) { ...         


        
相关标签:
2条回答
  • 2021-01-18 09:58

    You can use the meta character ^ to denote start of string. You can read more about it here. The following pattern will only match lg if it's in the start of the string:

    ^lg|iphone|blackberry|opera/
    

    You can see a simple example it in action here: http://regexr.com?2vjec

    0 讨论(0)
  • 2021-01-18 10:07

    I'm using this library to detect OS and browser info http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

    0 讨论(0)
提交回复
热议问题