Jump to content

Can I test for more than one value w/ "IF" or must test individually w/ "SWITCH"


Recommended Posts

Is it possible to test for more than one value in an "if" statement or must each desired value be checked individually with something like a "switch" or "if-else"?

 

For example, if I'm checking $_SERVER["$HTTP_USER_AGENT"] and I am only interested in selecting for Safari or Opera and all the rest are "else" ...?

 

BONUS question (for me ...)

 

And, can I get a clear answer on the best checker for this: strpos(), strstr(), substr(), or match_preg()??

 

Thank you

 

OMB

I use eregi for that type of stuff.

 

www.php.net/eregi  strstr can be deceiving in that if what you are looking for starts as the very first part of the string it returns 0, which coincidently also is considered to be false. eregi does not do that and it is case insensitive.

Thank you for the fast replies.  :-*

 

<?php

if((stripos($_SERVER[“$HTTP_USER_AGENT”], “opera”)) || (stripos($_SERVER[“$HTTP_USER_AGENT”], “safari”))) {
include("operasafari.css");
} else {
  include("otherbrowsers.css");
}

?>

Caveats duly noted ~ keep the included css as html inline styling. 

 

This makes perfect sense since I am only planning on changing 2 lines of css that are browser dependent. 

 

In fact, if this is the case, I only need to include ONE new css stylesheets as a result of the "IF" that holds the necessary browser dependent modifications of the otherwise already loaded stylesheet. 

 

So, I think the final version of the code will read:

<?php

if((stripos($_SERVER[“$HTTP_USER_AGENT”], “opera”)) || (stripos($_SERVER[“$HTTP_USER_AGENT”], “safari”))) {
include("operasafari.css");
} else {
}

?>

Thanx

 

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.