note 79875 added to function.getcwd
| From: | leonbrussels at gmail dot com | Date: | Mon, 17 Dec 2007 16:10:26 +0000 |
| Subject: | note 79875 added to function.getcwd | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133728@lists.php.net to get a copy of this message | ||
This is a function to convert a path which looks something like this:
/home/www/somefolder/../someotherfolder/../
To a proper directory path:
<?php
function simplify_path($path) {
//saves our current working directory to a variable
$oldcwd = getcwd();
//changes the directory to the one to convert
//$path is the directory to convert (clean up), handed over to the //function as a string
chdir($path);
return gstr_replace('\\', '/', getcwd());
//change the cwd back to the old value to not interfere with the script
chdir($oldcwd);
}
This function is really useful if you want to compare two filepaths which are not necesarily in a
"cleaned up" state. It works in *NIX and WINDOWS alike
?>
----
Server IP: 87.238.162.147
Probable Submitter: 84.192.154.85
----
Manual Page -- http://www.php.net/manual/en/function.getcwd.php
Edit -- https://master.php.net/note/edit/79875
Del: integrated -- https://master.php.net/note/delete/79875/integrated
Del: useless -- https://master.php.net/note/delete/79875/useless
Del: bad code -- https://master.php.net/note/delete/79875/bad+code
Del: spam -- https://master.php.net/note/delete/79875/spam
Del: non-english -- https://master.php.net/note/delete/79875/non-english
Del: in docs -- https://master.php.net/note/delete/79875/in+docs
Del: other reasons-- https://master.php.net/note/delete/79875
Reject -- https://master.php.net/note/reject/79875
Search -- https://master.php.net/manage/user-notes.php