0

我的网站上使用了此代码

if( isset($_GET['gw'] )){
  //this is some content
}

所以每当我的网址是这样的

http://mywebsite.com/?gw=hello

该 div 内的内容将出现。它工作得很好,但现在我想做的是为特定字符串提供不同的内容。像这样的东西

if (gw=hello) { 
 // content here
} else if (gw=goodbye) {
 // content here
} else {
 //content here
}

我知道那不是代码,但是有谁知道我可以做到这一点的方法吗?谢谢!

4

2 回答 2

2

你几乎在那里!

if(isset($_GET['gw'])) {

     if($_GET['gw'] == "hello") {

     }
     else if ($_GET['gw'] == "goodbye") {

     }
     else {

     }

}
于 2013-06-12T17:32:17.810 回答
1

最好使用switch语句,这样您将来可以轻松地扩展条件。

switch (isset($_GET['gw']) ? $_GET['gw'] : '')
{
    case "hello":
      // do something here
      break;

    case "goodbye":
      // do something here
      break;

    default:
      // default action if nothing above matches
      break;
}
于 2013-06-12T17:45:17.250 回答