2013-06-12 32 views
0

我有我的網站上如果動態URL是特定的,請執行此操作嗎?

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 
} 

我知道這不是代碼,但有沒有人知道我可以做到這一點?謝謝!

回答

2

你幾乎沒有!

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

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

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

    } 
    else { 

    } 

} 
+0

工作完美!謝謝! – JCBiggar

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; 
} 
+0

感謝您的支持!我可能會在某個時候使用它! – JCBiggar

相關問題