2017-03-02 52 views

回答

1

您可以使用parse_url從URL獲取路徑,然後用explode將其分割成其部分:

$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); 
$uri_segments = explode('/', $uri_path); 

echo $uri_segments[1]; // for www.example.com/category-b/post-name you will get 'category-b'. 
相關問題