By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

not show sub folders echo getcwd()

100+
P: 133
Hi guys i have searched and searched but i cannot work out how to only return the top folder eg this shows..
/home/username/public_html/dev/toolbar
i want to only show with no /
toolbar

Expand|Select|Wrap|Line Numbers
  1.                        <?php
  2.                         // current directory
  3.                         echo getcwd() . "\n";
  4.                        ?>
Thanks in advanced.
Gobble.
Apr 18 '10 #1

✓ answered by Atli

Hey.

To get only the "toolbar" part of "/home/username/public_html/dev/toolbar" you can use the basename function.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dir = '/home/username/public_html/dev/toolbar';
  3. echo basename($dir);
  4. // Output: toolbar
  5. ?>

Share this Question
Share on Google+
4 Replies


nouras
P: 15
This is not hard but take time to work,so i will give you an idea to try it yourself.
the idea :
make the "/" character is the key of the array(using function i don't remember it)
for example ::
the array is
/home/username/public_html/dev/toolbar

if the "/" is the key so ==>> array[0]=home
array[1]=username
array[2]=public_html

if you want only last one you have to count the array element(also function)
example
this array
/home/username/public_html/dev/toolbar
$count =5;(because the / is the key)

so you get $count-1=4 ===>>> array[4]

i am sorry but if i remember functions i will tell you..
Try to think about it yourself..
Apr 18 '10 #2

Atli
Expert 5K+
P: 5,058
Hey.

To get only the "toolbar" part of "/home/username/public_html/dev/toolbar" you can use the basename function.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dir = '/home/username/public_html/dev/toolbar';
  3. echo basename($dir);
  4. // Output: toolbar
  5. ?>
Apr 18 '10 #3

nouras
P: 15
@Atli
thanx Atli....
Apr 18 '10 #4

100+
P: 133
@Atli
Thanks Alti that is exactly what i needed i did look basename before this post but i couldnt make sense from it, so i was looking into using
Expand|Select|Wrap|Line Numbers
  1. string dirname ( string $path )
but i dont need to now. Thank you!
Apr 18 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.