This question already has an answer here:
- Function eregi() is deprecated 3 answers
- How can I convert ereg expressions to preg in PHP? 4 answers
I have a function to detect browser with version:
# 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';
}
I need to replace the eregi() function with preg_match() function. Because eregi() is deprecated in PHP 5.3.
But if i replace this function with pregmatch() i get many errors: Warning: preg_match(): Unknown modifier '|'....
Warning: preg_match(): Unknown modifier '|'....
Warning: preg_match(): Unknown modifier '('....
Warning: preg_match(): Unknown modifier '('....
How can i fix this?