如何将请求uri分离为for循环以分解变量


how to separate the request uri into a for loop to break down variables

我需要分解REQUEST_URI,为斜杠之间的每个字符串执行一些函数

从url传递的请求看起来像下面的url,但我不能给它们分配静态变量,因为每个不同的页面的url可能会变长或变短

https://www.domain.com/accounts/customers/details

我想做的是捕捉"账户/客户/详细信息"部分,我已经通过页面上的这个变量完成了这一部分

$requested_url = $_SERVER['REQUEST_URI']; // this outputs /accounts/customers/details

我希望创建一个for循环,从括号之间提取信息,并将其显示在类似的页面上

accounts
customers
details

如何实现

尝试这个

$requested_url = $_SERVER['REQUEST_URI'];
$seperate = explode("/",$requested_url); //this will explode in to array with "/" seperator
foreach($seperate as $seprt) { 
  echo $seprt."<br/>"; //it echo's each array variable seperately
}
$requested_url = $_SERVER['REQUEST_URI'];
$seperate = explode("/",$requested_url);
$count = 0;
foreach($seperate as $seprt) {
    $count++;
    if($count == count($seperate)){
         echo $seprt;
    }
}