如果语句检测到当前的服务器子域?

试图写一个PHP的if else声明沿线:

if ($_SERVER['SERVER_NAME'] = local ) { Content here should display if the current url is for example, local.test.com } elseif ($_SERVER['SERVER_NAME'] = stage) Content here should display if the current url is for example, stage.test.com } else { Content here should display if the current url is for example, test.com } 

我假设($ _SERVER ['SERVER_NAME'] =本地)和($ _SERVER ['SERVER_NAME'] =阶段)是不正确的,所以希望有人知道确切的语法。 谢谢!

你可以用一个switch语句来做,并使用默认的情况来做到这一点:-) http://php.net/manual/en/control-structures.switch.php

我不确定你是否有意这样做,但你需要一个双“平等”的标志来testing的价值,你也需要把你的价值引号之间:

 if ($_SERVER['SERVER_NAME'] == 'local' ) {....