note 95405 added to function.getcwd

From: Date: Fri, 01 Jan 2010 11:18:19 +0000
Subject: note 95405 added to function.getcwd
Groups: php.notes 
Request: Send a blank email to php-notes+get-164509@lists.php.net to get a copy of this message
It might be more expedient to use explode if you want to preserve the (e.g.) 2nd-to-last folder name before the function output loads. In that case, initialize an array and save the desired folder name from the get-go: $namedir = array(); //initialize $pathname = getcwd() ; // path named in main script $newpath = str_replace('\\','/',$pathname,$count) ; $namedir = explode("/",$newpath) ; //parse subfolders $foldername = $namedir[count($namedir)-2] ; //2nd-to-last folder Depending on your system, it may be possible to use dirname instead of $pathname=getcwd() but if you want to do this with local variables then the path still needs to be exploded prior to loading the function results: $pathname = dirname(__FILE__) ; // also works In my case the folder named \waterfalls\ needed to be extracted from this string: C:\xampp\htdocs\mydomain.com\\waterfalls\files\high.JPG ---- Server IP: 64.71.164.2 Probable Submitter: 207.118.122.175 ---- Manual Page -- http://www.php.net/manual/en/function.getcwd.php Edit -- https://master.php.net/note/edit/95405 Del: integrated -- https://master.php.net/note/delete/95405/integrated Del: useless -- https://master.php.net/note/delete/95405/useless Del: bad code -- https://master.php.net/note/delete/95405/bad+code Del: spam -- https://master.php.net/note/delete/95405/spam Del: non-english -- https://master.php.net/note/delete/95405/non-english Del: in docs -- https://master.php.net/note/delete/95405/in+docs Del: other reasons-- https://master.php.net/note/delete/95405 Reject -- https://master.php.net/note/reject/95405 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164509) next »