完整网址:http://www.somepage.com/admin/index.php?do=manageNews&search=1&sort=title&order=ASC
如何仅检索此部分:index.php?do=manageNews&search=1&sort=title&order=ASC
答案 0 :(得分:0)
您可以使用parse_url()
和pathinfo()
功能的组合,如下所示:
$url = 'http://www.somepage.com/admin/index.php?do=manageNews&search=1&sort=title&order=ASC';
# retrieve index.php file name using pathinfo() and parse_url()
$file = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_BASENAME);
# retrive query string using parse_url()
$query = parse_url($url, PHP_URL_QUERY);
# combine file name and query string.
if (strlen($query)>0) {
$file .= '?' . $query;
}
echo "$file\n"; # index.php?do=manageNews&search=1&sort=title&order=ASC