2011-03-11 77 views
1

有一個問題在這些地方

$_SERVER['REQUEST_URI'] 

被吐出: /dev/nava2/store/index.php?route=product/product&product_id=48

實際的URL /dev/nava2/store/index.php?route=product/product&product_id=48

很明顯,區別在於頂部的&與底部的&

full co de看起來像這樣:

$currentpage = $_SERVER['REQUEST_URI']; 
$classic = "/dev/nava2/store/index.php?route=product/product&product_id=48"; 


if ($currentpage == $classic) 
    { $classicclass = "current"; 

    } 

else { echo "";} 

有什麼建議嗎?

回答

4

&是對應於&的html實體。您可以獲取到初始字符串與html_entity_decode

$original = html_entity_decode($_SERVER['REQUEST_URI']); 
+0

這個伎倆!感謝將在5標記爲正確。 – 2011-03-11 20:49:02

+0

並且url不應該包含'&'而是'&',然而大多數瀏覽器/ web服務器將會努力糾正用戶輸入...參見[w3c附錄B:§B.2.2](http ://www.w3.org/TR/html4/appendix/notes.html#hB.2.2)。 – 2012-10-27 13:00:26

1
echo html_entity_decode($_SERVER['REQUEST_URI']); 
+0

這不會工作,根據http://php.net/manual/en/function.urldecode.php urldecode只解碼%##編碼。 – krtek 2011-03-11 20:46:59

+0

@Krtek - 你是對的 - 編輯。 – DeaconDesperado 2011-03-11 20:55:11

+0

謝謝你的嘗試。看起來我們都學到了一些東西! – 2011-03-11 20:58:50

1

您可以使用html_entity_decode()獲得實際的URL,但最上面的一個應該工作。我不認爲你需要改變任何事情。如果你真的需要改變你的uri的某些部分,你也可以使用str_replace或preg_replace。