2014-05-12 68 views
0

我的網站就像?dir =/friends/pending,我想知道我是否可以得到字符串的「朋友」部分?PHP獲取斜槓字符串的一部分

我嘗試到目前爲止

//I got the "pending" part by below... 
$val = substr($_GET['a'], strrpos($_GET['a'], '/')+1); 

//I tried getting "friends" with this but it didnt give me what i wanted.. 
$val2 = substr($_GET['a'], strrpos($_GET['a'], '/')- $val -2); 
+0

http://www.php.net/manual/en/ function.explode.php – CBroe

回答

0

你可以使用PHP的explode

$pieces = explode('/', $_GET['a']); 

# $pieces[1] = 'friends' 

參見文檔:http://www.php.net/explode

+0

謝謝!這爲我解決了它。 – user3626795