title: Remove parent folder from $_SERVER['REQUEST_URI'];
body: <p>I want to remove the first folder outputted by $_SERVER['REQUEST_URI'];</p>
  
  <pre><code>// I use it as language switcher in my website, here's how it works:
  
  &lt;?php $currenturl=$_SERVER['REQUEST_URI']; ?&gt;
  
  &lt;a href="https://mysite.com/&lt;?php echo $currenturl ?&gt;"&gt;United States&lt;/a&gt;
  &lt;a href="https://mysite.com/ca&lt;?php echo $currenturl ?&gt;"&gt;Canada&lt;/a&gt;
  &lt;a href="https://mysite.com/br&lt;?php echo $currenturl ?&gt;"&gt;Brasil&lt;/a&gt;
  </code></pre>
  
  <p>The problem is, in Canada for example, it outputs:</p>
  
  <p><a href="https://mysite.com/ca/ca/mypage" rel="nofollow">https://mysite.com/ca/ca/mypage</a></p>
  
  <p>It should be</p>
  
  <p><a href="https://mysite.com/ca/mypage" rel="nofollow">https://mysite.com/ca/mypage</a></p>