Jeniveve Posted April 23, 2007 Share Posted April 23, 2007 I have created a simple browser and platform detect script that a few people here helped me with a couple days ago. Everything was working great until I tried to add a preg_match statement to detect a safari browser on a mac. For some reason, no matter what string I use from the http_user_agent information for safari, I cannot get the script to detect safari on a mac... Could someone assist me with this one statement? The entire script is below but the line of code that will not work is as follows: /* Check for Safari on Macintosh: I also tried Gecko given phpinfo returned this value for http_user_agent, Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3 */ } elseif (preg_match('/Safari(?:.*)Macintosh/i', $_SERVER['HTTP_USER_AGENT'])) { echo '<link rel="stylesheet" type="text/css" href="macsaf_styles.css" />'; The entire script looks like this: <?php /* First check for IE on Win */ if (preg_match('/MSIE(?:.*)Win/i', $_SERVER['HTTP_USER_AGENT'])) { echo '<link rel="stylesheet" type="text/css" href="win_styles.css" />'; /* Check for Safari on Macintosh: I also tried Gecko given phpinfo returned this value for http_user_agent, Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3 */ } elseif (preg_match('/Safari(?:.*)Macintosh/i', $_SERVER['HTTP_USER_AGENT'])) { echo '<link rel="stylesheet" type="text/css" href="macsaf_styles.css" />'; /* Then check for Firefox on Macintosh */ } elseif (preg_match('/Mozilla(?:.*)Macintosh/i', $_SERVER['HTTP_USER_AGENT'])) { echo '<link rel="stylesheet" type="text/css" href="macfire_styles.css" />'; /* Then direct everything else to the default page... */ }else{ echo '<link rel="stylesheet" type="text/css" href="styles.css" />'; } ?> Any assistance with this would be extremely helpful. Thank you in advance! Jennifer Link to comment https://forums.phpfreaks.com/topic/48325-assistance-in-getting-elseif-statement-to-work/ Share on other sites More sharing options...
marmite Posted April 23, 2007 Share Posted April 23, 2007 Think you're missing an } Should it read: } elseif { Hope that helps! Emma Link to comment https://forums.phpfreaks.com/topic/48325-assistance-in-getting-elseif-statement-to-work/#findComment-236279 Share on other sites More sharing options...
Jeniveve Posted April 23, 2007 Author Share Posted April 23, 2007 Thanks for the comment Emma however, every if elseif else statement I have ever written reads like this: if { echo.. } elseif (conditional statement) { echo.. } elseif (conditional) { } else { I looked over my code and I can't seem to find any missing brackets, can you be more specific as to exactly where you think the missing ones should go? Thank you, Jen Think you're missing an } Should it read: } elseif { Hope that helps! Emma Link to comment https://forums.phpfreaks.com/topic/48325-assistance-in-getting-elseif-statement-to-work/#findComment-236328 Share on other sites More sharing options...
marmite Posted April 24, 2007 Share Posted April 24, 2007 No, you're quite right - I missed the { you had at the end. My mistake. Clearly the IF is working anyway, it's the pregmatch that isn't (and that's a function I've never used). Sorry! Link to comment https://forums.phpfreaks.com/topic/48325-assistance-in-getting-elseif-statement-to-work/#findComment-236772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.