Home > php教程 > php手册 > body text

获取客户端浏览器信息

WBOY
Release: 2016-06-07 11:45:47
Original
984 people have browsed it

/**<br>  * 获取客户端浏览器类型<br>  * @param  string $glue 浏览器类型和版本号之间的连接符<br>  * @return string|array 传递连接符则连接浏览器类型和版本号返回字符串否则直接返回数组 false为未知浏览器类型<br>  */<br> function get_client_browser($glue = null) {<br>     $browser = array();<br>     $agent = $_SERVER['HTTP_USER_AGENT']; //获取客户端信息<br>     <br>     /* 定义浏览器特性正则表达式 */<br>     $regex = array(<br>         'ie'      => '/(MSIE) (\d+\.\d)/',<br>         'chrome'  => '/(Chrome)\/(\d+\.\d+)/',<br>         'firefox' => '/(Firefox)\/(\d+\.\d+)/',<br>         'opera'   => '/(Opera)\/(\d+\.\d+)/',<br>         'safari'  => '/Version\/(\d+\.\d+\.\d) (Safari)/',<br>     );<br> <br>     foreach($regex as $type => $reg) {<br>         preg_match($reg, $agent, $data);<br>         if(!empty($data) && is_array($data)){<br>             $browser = $type === 'safari' ? array($data[2], $data[1]) : array($data[1], $data[2]);<br>             break;<br>         }<br>     }<br> <br>     return empty($browser) ? false : (is_null($glue) ? $browser : implode($glue, $browser));<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!