Hey all, once again I turn to the experts for some help. Y'all have been very useful and a great help in my learning php endeavors. The job I have pretty much pushed me head first into php with minimal knowledge so I need to come here at times for some help.
I have written a script to help determine the browser and put that into a variable. I then want to use this variable to help determine which section of code to run..for example if ($browser == IE){ do this code}else{ do this code}
Here is the script I wrote:
<?php
$useragent = $_SERVER[‘HTTP_USER_AGENT’];
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= ‘other’;
}
echo 'browser: ' . $browser $browser_version;
?>
When I run it I get this error but cannot find what it is talking about:
Parse error: parse error, unexpected '[', expecting ')' in c:\program files\apache group\Apache\htdocs\browser_detect2.php on line 4
If y'all can even just point me in the right direction with out giving me the straight out answer (this way I learn something) I would be grateful!!
I have written a script to help determine the browser and put that into a variable. I then want to use this variable to help determine which section of code to run..for example if ($browser == IE){ do this code}else{ do this code}
Here is the script I wrote:
<?php
$useragent = $_SERVER[‘HTTP_USER_AGENT’];
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= ‘other’;
}
echo 'browser: ' . $browser $browser_version;
?>
When I run it I get this error but cannot find what it is talking about:
Parse error: parse error, unexpected '[', expecting ')' in c:\program files\apache group\Apache\htdocs\browser_detect2.php on line 4
If y'all can even just point me in the right direction with out giving me the straight out answer (this way I learn something) I would be grateful!!