用php识别opera浏览器

用php识别opera浏览器,php,css,browser,opera,Php,Css,Browser,Opera,我将此php代码用于识别浏览器 $ua = $_SERVER['HTTP_USER_AGENT']; if(preg_match("/\bOpera\b/i", $ua)==TRUE){ echo '<link href="stili/opera.css" type="text/css" rel="stylesheet"/>'; }elseif(preg_match("/\bMSIE\b/i", $ua)==TRUE){ echo '<link href="st

我将此php代码用于识别浏览器

$ua = $_SERVER['HTTP_USER_AGENT'];
if(preg_match("/\bOpera\b/i", $ua)==TRUE){
    echo '<link href="stili/opera.css" type="text/css" rel="stylesheet"/>';
}elseif(preg_match("/\bMSIE\b/i", $ua)==TRUE){
    echo '<link href="stili/ie.css" type="text/css" rel="stylesheet"/>';
}elseif(preg_match("/\bSafari\b/i", $ua)==TRUE){
    echo '<link href="stili/safari.css" type="text/css" rel="stylesheet"/>';
}elseif(preg_match("/\bFirefox\b/i", $ua)==TRUE){
    echo '<link href="stili/moz.css" type="text/css" rel="stylesheet"/>';
}else
    echo '<link href="stili/main.css" type="text/css" rel="stylesheet"/>';
$ua=$\u服务器['HTTP\u用户\u代理];
if(preg_match(“/\bOpera\b/i,$ua)==TRUE){
回声';
}elseif(preg_match(“/\bMSIE\b/i”,$ua)=TRUE){
回声';
}elseif(preg_match(“/\bSafari\b/i”,$ua)=TRUE){
回声';
}elseif(preg_match(“/\bFirefox\b/i”,$ua)=TRUE){
回声';
}否则
回声';

适用于所有浏览器,但不适用于Opera。如何解决?

更简单的方法是使用PHP函数get_browser()()


opera用户代理字符串中必须包含单词opera,这不是强制性的。

1。使用,2。编写正确的css,您就不需要这样做了。我得到了以下错误警告:get_browser()[function.get browser]:在第4行的C:\AppServ\www\test.php中未设置browscap ini指令阅读文档是好的,但解决css问题的浏览器嗅探是坏的。你想解决的真正问题是什么?对于哪个版本的Opera?得到以下错误警告:get_browser()[function.get browser]:未在第2行的C:\AppServ\www\test.php中设置browsercap ini指令您需要在php.ini文件中设置browsercap指令
<?php
$browser = get_browser(null, true);

echo $browser["browser"];
?>