note 14008 added to function.realpath.php

From: Date: Fri, 13 Jul 2001 08:17:38 +0000
Subject: note 14008 added to function.realpath.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15317@lists.php.net to get a copy of this message
I've come to the conclusion realpath is not very useful. Here is a *quick and dirty replacement* I wrote which fixes ../ and ./ for a given passed string. function TruePath ($path){ //Not really optimized but it does work. $patharray = explode ("/", $path); $path="";$count=count($patharray);//We have multiple count($patharray) so a minor bit faster. for ($i=0;$i<$count; $i++){ if ( $patharray[$i] == "." || $patharray[$i]== ".." || ( (($i+1) < $count) && ($patharray[$i+1]== "..")) ) { //If the current pos is a . ignore, if pos+1 == .. ignore, lastly if current = .. ignore. } else { $path .= $patharray[$i]."/"; } } //Trim trailing slash $path = substr($path,0,-1); return ($path); } http://www.php.net/manual/en/function.realpath.php

« previous php.notes (#15317) next »