PHP使用斜杠获取字符串的一部分

时间:2014-05-12 01:30:08

标签: php

我的网站就像?dir = / friends / pending,我想知道我是否只能获得字符串中的“朋友”部分?

到目前为止我的尝试

//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 );

1 个答案:

答案 0 :(得分:0)

您可以使用PHP的explode

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

# $pieces[1] = 'friends'

请参阅文档:http://www.php.net/explode