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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.