1

バージョンでブラウザを検出する機能があります:

    # Agent - Webbrowsers
    function agent_browser($http_user_agent) {

        // Browsers
        $browsers = array (
            'Android Standaard' => '(Linux)(.*)(Android)(.*)(Mobile Safari)',
            'MSIE 10' => '(MSIE 10)',
            'MSIE 9' => '(MSIE 9)',
            'MSIE 8' => '(MSIE 8)',
            'MSIE 7' => '(MSIE 7)',
            'MSIE 6' => '(MSIE 6)',
            'MSIE 5' => '(MSIE 5)',
            'Opera 12' => '(Opera 12)|(Opera/)(.*)(Version/12)',
            'Opera 11' => '(Opera 11)|(Opera/)(.*)(Version/11)',
            'Opera 10' => '(Opera 10)|(Opera/)(.*)(Version/10)',
            'Opera 9' => '(Opera 9)|(Opera/9)|(Opera/)(.*)(Version/9)',
            'Opera 8' => '(Opera 8)|(Opera/8)|(Opera/)(.*)(Version/8)',
            'Firefox 25' => '(Firefox/25)',
            'Firefox 24' => '(Firefox/24)',
            'Firefox 23' => '(Firefox/23)',
            'Firefox 22' => '(Firefox/22)',
            'Firefox 21' => '(Firefox/21)',
            'Firefox 20' => '(Firefox/20)',
            'Firefox 19' => '(Firefox/19)',
            'Firefox 18' => '(Firefox/18)',
            'Firefox 17' => '(Firefox/17)',
            'Firefox 16' => '(Firefox/16)',
            'Firefox 15' => '(Firefox/15)',
            'Firefox 14' => '(Firefox/14)',
            'Firefox 13' => '(Firefox/13)',
            'Firefox 12' => '(Firefox/12)',
            'Firefox 11' => '(Firefox/11)',
            'Firefox 10' => '(Firefox/10)',
            'Firefox 9' => '(Firefox/9)',
            'Firefox 8' => '(Firefox/8)',
            'Firefox 7' => '(Firefox/7)',
            'Firefox 6' => '(Firefox/6)',
            'Firefox 5' => '(Firefox/5)',
            'Chrome 29' => '(Chrome/29)',
            'Chrome 28' => '(Chrome/28)',
            'Chrome 27' => '(Chrome/27)',
            'Chrome 26' => '(Chrome/26)',
            'Chrome 25' => '(Chrome/25)',
            'Chrome 24' => '(Chrome/24)',
            'Chrome 23' => '(Chrome/23)',
            'Chrome 22' => '(Chrome/22)',
            'Chrome 21' => '(Chrome/21)',
            'Chrome 20' => '(Chrome/20)',
            'Chrome 19' => '(Chrome/19)',
            'Chrome 18' => '(Chrome/18)',
            'Chrome 17' => '(Chrome/17)',
            'Chrome 16' => '(Chrome/16)',
            'Chrome 15' => '(Chrome/15)',
            'Chrome 14' => '(Chrome/14)',
            'Chrome 13' => '(Chrome/13)',
            'Chrome 12' => '(Chrome/12)',
            'Chrome 11' => '(Chrome/11)',
            'Chrome 10' => '(Chrome/10)',
            'BlackBerry 7' => '(BlackBerry)(.*)(Version/7)',
            'BlackBerry 6' => '(BlackBerry)(.*)(Version/6)',
            'Nokia 8' => '(BrowserNG/8)|(NokiaBrowser/8)',
            'Nokia 7' => '(BrowserNG/7)|(NokiaBrowser/7)',
            'Safari 7' => '(Version/7)(.*)(Safari/)',
            'Safari 6' => '(Version/6)(.*)(Safari/)',
            'Safari 5' => '(Version/5)(.*)(Safari/)',
            'Safari 4' => '(Version/4)(.*)(Safari/)',
            'Safari 3' => '(Version/3)(.*)(Safari/)',
            'Safari 2' => '(Version/2)(.*)(Safari/)',
            'Safari 1' => '(Version/1)(.*)(Safari/)'
        );


        foreach($browsers as $browser => $pattern){

            if(eregi($pattern, $http_user_agent)) {
                return $browser;
            }

        }

        return 'Unknown';
    }

eregi() 関数を preg_match() 関数に置き換える必要があります。eregi() は PHP 5.3 で非推奨になったためです。

しかし、この関数を pregmatch() に置き換えると、多くのエラーが発生します: 警告: preg_match(): 不明な修飾子 '|'....

Warning: preg_match(): Unknown modifier '|'....
Warning: preg_match(): Unknown modifier '('....
Warning: preg_match(): Unknown modifier '('....

どうすればこれを修正できますか?

4

2 に答える 2

1

先頭と末尾のすべてのパターンを同じ区切り記号に置き換えます。

        'MSIE 10' => '/(MSIE 10)/',
        'MSIE 9' => '/(MSIE 9)/',
        'MSIE 8' => '/(MSIE 8)/',
        'MSIE 7' => '/(MSIE 7)/',

等々...

于 2014-01-08T11:44:10.323 に答える