Posted By

Mithun on 10/09/09


Tagged

fix url short slash shortner


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Mithun
pster


URL fix


 / Published in: PHP
 

URL: pms

shorts urls like http://example.com/abc/../123.html to http://example.com/123.html

  1. function url_fix($url){
  2. $pieces = explode("/", $url);
  3. foreach($pieces as $i=>$piece) {
  4. if($piece == '.'){
  5. unset($pieces[$i]);
  6. }
  7. if($piece == '..'){
  8. if(array_key_exists($i-1, $pieces)){
  9. unset($pieces[$i-1]);
  10. }
  11. }
  12. }
  13. return implode("/", $pieces);
  14. }

Report this snippet  

You need to login to post a comment.