Jump to content

assistance in getting elseif statement to work...


Jeniveve

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.