Is there a quintessential mobile User-Agent regexp pattern?

后端 未结 2 1081
小蘑菇
小蘑菇 2021-01-12 10:13

There are endless examples in the tubes of regexp patterns designed to detect mobile User-Agents, even quite a few in answers herein. Do you know of one that is perhaps most

2条回答
  •  無奈伤痛
    2021-01-12 10:57

    Disclaimer: I know this regex is not perfect/quintessential, so don't down vote just for that :)

    Just wanted to share these few points.

    1. Some servers have $_SERVER['HTTP_USER_AGENT'] as not set, so make sure to check if empty first
    2. Readability is important to us, so we are using this instead of others complex regex. Just add other devices as you see fit.

    Here is the code we use:

    
    

提交回复
热议问题