note 15029 added to function.pathinfo.php
| From: | m-symons at home dot com | Date: | Fri, 24 Aug 2001 22:54:10 +0000 |
| Subject: | note 15029 added to function.pathinfo.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17098@lists.php.net to get a copy of this message | ||
Here's a neat wee function to grab the relative path to root (especially useful if you're
using mock-directories to pass variables into scripts with mod_rewrite). The function simply
iterates through every occurence of "/" within the REQUEST_URI environment variable,
appending "../" to the output for every instance:
<?php
function path_to_root($path) {
$pathinfo = pathinfo($path);
$deep = substr_count($pathinfo[dirname], "/");
$path_to_root = "./";
for($i = 1; $i <= $deep; $i++) {
$path_to_root .= "../";
}
return $path_to_root;
}
path_to_root($REQUEST_URI);
?>
http://www.php.net/manual/en/function.pathinfo.php