note 16769 added to function.realpath

From: Date: Mon, 12 Nov 2001 23:07:26 +0000
Subject: note 16769 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-20768@lists.php.net to get a copy of this message
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); } -- http://www.php.net/manual/en/function.realpath.php http://master.php.net/manage/user-notes.php?action=edit+16769 http://master.php.net/manage/user-notes.php?action=delete+16769 http://master.php.net/manage/user-notes.php?action=reject+16769

« previous php.notes (#20768) next »