2011-07-13 32 views
1

籤我現在有這樣的代碼:全局變量,包括問號,等於在的preg_match

$uri = $_SERVER["REQUEST_URI"]; 
if (preg_match("/smda/", $uri)) { 
    echo "whatever; 
} 

其中捕捉包含「SMDA」的任何URL。我想縮小到任何包含src = smda的URL。我認爲代碼是這樣嗎?

$uri = $_SERVER["REQUEST_URI"]; 
if (preg_match("/src=smda/", $uri)) { 
    echo "whatever; 
} 

回答

3

適當,容易的是

if (isset($_GET['src']) && $_GET['src'] == 'smda') 
{ 
    echo "whatever"; 
} 
+0

如果SMDA在URL中存在,我不想用這個條件來使用?例如http://mydomain.com/smda-page – manc

+0

@亞歷山大:你沒有得到我,只有當URL包含像這樣的http://mydomain.com/somepage/?src=smda時,這個條件纔會成立。只有'smda'與'?'標記之後的'src'關聯,並且等號爲。嘗試一次,你會得到。 –

+0

因此,我不需要使用定義$ uri的第一行代碼? – manc