Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 24th, 2005, 08:51 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Current directory

Hopefully this is a simple question with a simple answer!

I need to extract the current directory into a variable. I can easily get the current working directory, but that contains the full path and I only want the last part of it,

e.g.

$folder=getcwd();
echo $folder;

c:\program files\apache group\apache\htdocs\bs\folder1

... when I really just want 'folder1'. Is there an easy way of doing this?



Richard H.
 
Old August 24th, 2005, 09:49 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've been given the following code which does the job:

<?php
$filepathone = $HTTP_SERVER_VARS["PHP_SELF"];
$filepathtwo = dirname($filepathone);
$filepaththree = dirname($filepathtwo);
$filepathfour = dirname($filepaththree);
$filenameone = basename($filepathone);
$filenametwo = basename($filepathtwo);
$filenamethree = basename($filepaththree);
$filenamefour = basename($filepathfour);
echo "<br />$filenametwo";
?>

Is there a more elegant way of doing this? I'm very happy to have got it working already, but it's always nice to find a smaller, tighter method if at all possible.


Richard H.
 
Old August 25th, 2005, 01:32 AM
jomet
Guest
 
Posts: n/a
Default

i dont know is this usefull for u?

$path_parts = pathinfo(getcwd());
echo basename($path_parts["dirname"]);
echo "<br>".$path_parts["basename"];

jomet.
 
Old August 25th, 2005, 10:05 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's great! Exactly what I was after! :D

Many Thanks,



Richard H.





Similar Threads
Thread Thread Starter Forum Replies Last Post
"for-the-current-node" instead of "for-each" ? webhead XSLT 2 August 25th, 2006 02:55 PM
Current printer name taraj ASP.NET 1.0 and 1.1 Basics 1 October 25th, 2004 08:10 AM
Getting the current month Regornil JSP Basics 1 July 19th, 2004 09:01 PM
current user schockp Oracle 2 November 12th, 2003 06:18 AM
Getting the current directory xgbnow Visual C++ 1 September 16th, 2003 02:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.