As strange as I find this, I have not been able to find a good PHP function anywhere which will do an intelligent parse of a user agent string? Googled it for about 20 minutes now.
奇怪的是,我在任何地方都找不到一个好的PHP函数来对用户代理字符串进行智能解析?用谷歌搜索了大约20分钟。
I have the string already, I just need something that will chop it up and give me at least browser/ver/os.
我已经有了这个字符串,我只需要一些东西把它切碎,至少给我浏览器/服务器/操作系统。
Know of a good snippet anywhere?
知道一个好的片段吗?
5 个解决方案
#1
22
The get_browser()
function has been available in PHP for quite a long a time.
get_browser()函数在PHP中已经使用了很长时间。
The PHP manual is free, can be downloaded in various formats and viewed online (with comments)
PHP手册是免费的,可以以各种格式下载并在线观看(有注释)
#2
11
https://github.com/browscap/browscap-php - this is a standalone library that aims to replace get_browser
function. For shared hostings it seems to be a better option.
这是一个旨在取代get_browser函数的独立库。对于共享主机,这似乎是一个更好的选择。
Works on: PHP 5
适用于:PHP 5
#3
2
You can try to use: https://github.com/tobie/ua-parser. This is multi-language tool to parsing user agent string. For PHP is here: https://github.com/tobie/ua-parser/tree/master/php
您可以尝试使用:https://github.com/tobie/ua-parser。这是解析用户代理字符串的多语言工具。PHP在这里:https://github.com/tobie/ua-parser/tree/master/php
#4
0
Try out ThaDafinser/UserAgentParser it's an abstraction for many available user agent parsers.
请尝试ThaDafinser/UserAgentParser,它是许多可用用户代理解析器的抽象。
So if you are not happy with one - just switch to another (or combine them)
因此,如果你对其中一个不满意,那就换另一个(或合并它们)
You can try it out here
你可以在这里试试
#5
0
There is a PHP class library i found out, and it has worked so well for me. It is in the link below.
我发现了一个PHP类库,它非常适合我。在下面的链接中。
https://www.toms-world.org/blog/parseuseragentstring
https://www.toms-world.org/blog/parseuseragentstring
It is lightweight and just does what I wanted (Browser, Version, OS, Mobile/PC, and much more) in a memory-friendy manner.
它是轻量级的,只做我想要的(浏览器、版本、操作系统、移动/PC,等等)。
#1
22
The get_browser()
function has been available in PHP for quite a long a time.
get_browser()函数在PHP中已经使用了很长时间。
The PHP manual is free, can be downloaded in various formats and viewed online (with comments)
PHP手册是免费的,可以以各种格式下载并在线观看(有注释)
#2
11
https://github.com/browscap/browscap-php - this is a standalone library that aims to replace get_browser
function. For shared hostings it seems to be a better option.
这是一个旨在取代get_browser函数的独立库。对于共享主机,这似乎是一个更好的选择。
Works on: PHP 5
适用于:PHP 5
#3
2
You can try to use: https://github.com/tobie/ua-parser. This is multi-language tool to parsing user agent string. For PHP is here: https://github.com/tobie/ua-parser/tree/master/php
您可以尝试使用:https://github.com/tobie/ua-parser。这是解析用户代理字符串的多语言工具。PHP在这里:https://github.com/tobie/ua-parser/tree/master/php
#4
0
Try out ThaDafinser/UserAgentParser it's an abstraction for many available user agent parsers.
请尝试ThaDafinser/UserAgentParser,它是许多可用用户代理解析器的抽象。
So if you are not happy with one - just switch to another (or combine them)
因此,如果你对其中一个不满意,那就换另一个(或合并它们)
You can try it out here
你可以在这里试试
#5
0
There is a PHP class library i found out, and it has worked so well for me. It is in the link below.
我发现了一个PHP类库,它非常适合我。在下面的链接中。
https://www.toms-world.org/blog/parseuseragentstring
https://www.toms-world.org/blog/parseuseragentstring
It is lightweight and just does what I wanted (Browser, Version, OS, Mobile/PC, and much more) in a memory-friendy manner.
它是轻量级的,只做我想要的(浏览器、版本、操作系统、移动/PC,等等)。