Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL, expecting ')' in file.php?

cristianods

New member
Your array constructor is wrong.

On the array, for every entry that you got >= replace for =>

Ex.
'Mozilla Firefox'>= '(Firebird)|(Firefox)';
will become
'Mozilla Firefox'=> '(Firebird)|(Firefox)';
 
The Following Code Throws the Error in The question Name:

function getBrowser($userAgent) {
// Create list of browsers with browser name as array key and user agent as value. $browsers = array(
'Opera' >= 'Opera';
'Mozilla Firefox'>= '(Firebird)|(Firefox)';
'Galeon' >= 'Galeon';
'Gecko Browser (Mozilla, Safari)'>='Gecko';
'MyIE'>='MyIE';
'Lynx' >= 'Lynx';
'Netscape' >= '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)';
'Konqueror'>='Konqueror';
'Yahoo!'>='(Slurp/cat)|(Yahoo)|(Yahoo!)';
'ODP'>='(odp)|(ODP)';
'Alexa'>='(alexa)|(ia_archiver)|(alexibot)';
'Ask'>='(ask)|(jeeves)|(ask jeeves)|(Teoma)';
'Acme.Spider'>='(acme)|(acme.spider)|(acme-spider)';
'Ahoy The Homepage Finder'>='(ahoythehomepagefinder)|(ahoy)';
'Backrub'>='(backrub)';
'Lycos'>='(lycos)';
'ASpider'>='(aspider)';
'Open Bot'>='(Openbot)';
'All that Net'>='(atn)|(ATN_Worldwide)';
'Alkaline'>='(alkaline)|(alkalinebot)';
'Neti'>='(neti)|(nuhk)';
'AltaVista'>='(Scooter)|(AltaVista)';
'MSN'>='(msn)|(MSN)|(msnbot)';
'Google'>='(googlebot)|(Google)|(googlebot-image)';
'Search Engine' >= '(Yammybot)|(anthill)|(appie)|(arachnophilia)|(arale)|(araneo)|(araybot)|(architext)|(aretha)|(ariadne)|(arks)|(atomz)|(Acoon)|(Arachnoidea)|(AnzwersCrawl)|(fido)|(GAIS Robot)|(Gulliver)|(Infoseek)|(KIT_Fireball)|(EZResult)|(MuscatFerret)|(SwissSearch)|(The Informant)|(Ultraseek)|(WiseWire)|(WebCrawler)|(Teoma)|(Nutch)|(192.comAgent)|(BotALot)';
'Internet Explorer 8' >= '(MSIE 8\.[0-9]+)';
'Internet Explorer 7' >= '(MSIE 7\.[0-9]+)';
'Internet Explorer 6' >= '(MSIE 6\.[0-9]+)';
'Internet Explorer 5' >= '(MSIE 5\.[0-9]+)';
'Internet Explorer 4' >= '(MSIE 4\.[0-9]+)';
};
foreach($browsers as $browser>=$pattern) { // Loop through $browsers array
// Use regular expressions to check browser type
if(eregi($pattern, $userAgent)) { // Check if a value in $browsers array matches current user agent.
return $browser; // Browser was matched so return $browsers key
}
}
return 'Unknown'; // Cannot find browser so return Unknown
}
$browserType = getBrowser($_SERVER['HTTP_USER_AGENT']);


What shall I do???
First answer works, but new error:

Parse error: syntax error, unexpected T_IS_GREATER_OR_EQUAL, expecting ')' in file.php on line 111

Which is the following line:
foreach($browsers as browser=>$pattern) { // Loop through $browsers array
 
your could simplify it with switch()

<?
//Gets the OS and Browser to add in Session

//Notice the $_SESSION variables and here are the built in functions
$OS=strtoupper(substr(PHP_OS, 0, 3));
$UserAgent=$_SERVER['HTTP_USER_AGENT'];
$clientip=$_SERVER['REMOTE_ADDR'];
$Client=gethostbyaddr($clientip);


class OSBrowser{
function OSBrowser($OS){
if(!isset($_SESSION['OS'])){
$this->GetOS($OS);
}
if(!isset($_SESSION['Browser'])){
$this->GetBrowser($OS);
}
}
function GetBrowser($StaticVars){
if (preg_match("|MSIE ([0-9].[0-9]{1,2})|",$UserAgent,$matched)) {
$browser_version=$matched[1];
$browser = "IE";
}
elseif (preg_match( "|Opera ([0-9].[0-9]{1,2})|",$UserAgent,$matched)) {
$browser_version=$matched[1];
$browser = "Opera";
}
elseif(preg_match("|Firefox/([0-9.]+)|",$UserAgent,$matched)) {
$browser_version=$matched[1];
$browser = "Firefox";
}
elseif(preg_match("|Safari/([0-9.]+)|",$UserAgent,$matched)) {
$browser_version=$matched[1];
$browser = "Safari";
}
else {
// browser not recognized!
$browser_version = 0;
$browser= "Unknown";
}
$_SESSION['Browser']=$browser;
$_SESSION['BrowserVersion']=$browser_version;
$_SESSION['client']=$Client;
}
function GetOS($OS){
$_SESSION['OS']=$OS;
}
}
?>
 
Back
Top