note 108166 added to directoryiterator.getpath

From: Date: Wed, 04 Apr 2012 12:19:23 +0000
Subject: note 108166 added to directoryiterator.getpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-186957@lists.php.net to get a copy of this message
If you wish to get a part of path you can use function like this: <?php /** * Return a part of path by depth * * @param $path string * @param $depth int * @return mixed string on success, false on failure */ function getPartPath($path = '', $depth = 0) { $pathArray = array(); $pathArray = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR)); if($depth < 0) $depth = count($pathArray)+$depth; if(!isset($pathArray[$depth])) return false; return $pathArray[$depth]; } ?> usage: <?php $a = "/var/www/foo/trunk/bar/tools/php/simplelocal"; var_dump(getPartPath($a, -2)); // returns php var_dump(getPartPath($a, 0)); // returns var var_dump(getPartPath($a, -1)); // returns simplelocal ?> etc... Regards. ---- Server IP: 69.147.83.197 Probable Submitter: 89.69.148.98 ---- Manual Page -- http://www.php.net/manual/en/directoryiterator.getpath.php Edit -- https://master.php.net/note/edit/108166 Del: integrated -- https://master.php.net/note/delete/108166/integrated Del: useless -- https://master.php.net/note/delete/108166/useless Del: bad code -- https://master.php.net/note/delete/108166/bad+code Del: spam -- https://master.php.net/note/delete/108166/spam Del: non-english -- https://master.php.net/note/delete/108166/non-english Del: in docs -- https://master.php.net/note/delete/108166/in+docs Del: other reasons-- https://master.php.net/note/delete/108166 Reject -- https://master.php.net/note/reject/108166 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186957) next »