解析用户代理字符串的代码?
正如我发现的那样,我一直无法在任何地方找到一个好的 PHP 函数来对用户代理字符串进行智能解析?谷歌搜索了大约20分钟。
我已经有了字符串,我只需要一些可以将其切碎并至少给我浏览器/版本/操作系统的东西。
知道任何地方的好片段吗?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
get_browser()
函数已可用在 PHP 中使用了很长一段时间。PHP手册是免费的,可以多种格式下载并在线查看(带注释)
The
get_browser()
function has been available in PHP for quite a long a time.The PHP manual is free, can be downloaded in various formats and viewed online (with comments)
https://github.com/browscap/browscap-php - 这是一个独立的库,旨在替换
get_browser
函数。对于共享主机来说,这似乎是一个更好的选择。适用于:PHP 5
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.Works on: PHP 5
您可以尝试使用:https://github.com/tobie/ua-parser。这是解析用户代理字符串的多语言工具。对于 PHP 在这里: https://github.com/tobie/ua-parser/树/master/php
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
尝试 ThaDafinser/UserAgentParser 它是许多可用用户代理解析器的抽象。
因此,如果您对其中一个不满意 - 只需切换到另一个(或将它们组合起来)
您可以在这里尝试
Try out ThaDafinser/UserAgentParser it's an abstraction for many available user agent parsers.
So if you are not happy with one - just switch to another (or combine them)
You can try it out here
我发现了一个 PHP 类库,它对我来说非常有效。它在下面的链接中。
https://www.toms-world.org/blog/parseuseragentstring
它是轻量级的并且以一种内存友好的方式执行我想要的操作(浏览器、版本、操作系统、移动/PC 等等)。
There is a PHP class library i found out, and it has worked so well for me. It is in the link below.
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.