I have a variable $A = "someword"; I would like to use this kind of format: If $_SERVER["SERVER_NAME"] = 1 THEN $A = One If $_SERVER["SERVER_NAME"] = 2 THEN $A = Two If $_SERVER["SERVER_NAME"] = 3 THEN $A = Three Etc... Any idea how to do that? I've tried preg_match but I think I got it wrong trying to preg_match the server seems to be a long way around.
//you could try something like this... switch($_SERVER['SERVER_NAME']){ case "www.yoursite.com": $a = "server one"; break; case "www.mysite.com": $a = "server two"; break; } //echo or do whatever you want with $a here... PHP:
Yes, a case switch would be better. If you are going to use the If Then statements, you need to use == to evaluate, not = (which assigns). i.e. If ($_SERVER['SERVER_NAME'] == 1) { ..... }
you could also store the values of $A in an array, with the server domain as key: $A_values = array('www.server1.com' => 'server one', 'www.server2.com' => 'server two', ' etc.' => 'etc.'); if (array_key_exists($_SERVER['SERVER_NAME'], $A_values) { $A = $A_values[$_SERVER['SERVER_NAME']]; } PHP: this saves some time if you want to add hundreds of server names , and is easier to edit later on
it's gonna take a while to catch up with you Anyway, this forum is freaky: you go off for 20 minutes, and people allready posted a 100 new posts. So i guess there will be plenty of posts left for you