2014-05-12 30 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