note 16769 deleted from function.realpath by aidan

From: Date: Sun, 29 Aug 2004 21:52:14 +0000
Subject: note 16769 deleted from function.realpath by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75625@lists.php.net to get a copy of this message
Note Submitter: justink at wafishermn dot com ---- For those of us that want to translate the string even if the path doesn't exist: /* array str2path(string $path_str) Does the same thing as the function realpath(), except it will also translate paths that don't exist on the system. returns an array of 2 elements. [0] = the translated string; [1] = TRUE|FALSE which indicates if it exists on the system. Derived from make_path written by "Jon Kraft" <sherq@yahoo.de> - Justin Koivisto <justink@wafishermn.com> */ function str2path($path_str){ $pwd=realpath($path_str); $EX_FLAG=TRUE; if(empty($pwd)){ $EX_FLAG=FALSE; $pwd=''; $strArr=preg_split("/(\/)/",$path_str,-1,PREG_SPLIT_NO_EMPTY); $pwdArr=""; $j=0; for($i=0;$i<count($strArr);$i++){ if($strArr[$i]!=".."){ if($strArr[$i]!="."){ $pwdArr[$j]=$strArr[$i]; $j++; } }else{ array_pop($pwdArr); $j--; } } $pStr=implode("/",$pwdArr); $pwd=(strlen($pStr)>0) ? ("/".$pStr) : "/"; } return array(0=>$pwd,1=>$EX_FLAG); }

« previous php.notes (#75625) next »