Concatenate file paths


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // from http://kendsnyder.com/posts/pathconcat
  2. function pathConcat(/*path1, $path2[, $path3][, $pathN]*/) {
  3. $parts = func_get_args();
  4. $base = array_shift($parts);
  5. $base = str_replace('\/',"\x01",$base);
  6. $base = rtrim($base, '/');
  7. $paths = array();
  8. foreach ($parts as $part) {
  9. $part = str_replace('\/',"\x01",$part);
  10. $part = trim($part, '/');
  11. if (strlen($part)) {
  12. $paths[] = $part;
  13. }
  14. }
  15. $fullpath = join($paths, '/');
  16. $fullpath = $base . '/' . $fullpath;
  17. $fullpath = str_replace("\x01",'\/',$fullpath);
  18. return $fullpath;
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.