not show sub folders echo getcwd()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    not show sub folders echo getcwd()

    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

    Code:
                           <?php
                            // current directory
                            echo getcwd() . "\n";
                           ?>
    Thanks in advanced.
    Gobble.
  • nouras
    New Member
    • Apr 2010
    • 15

    #2
    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..

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      To get only the "toolbar" part of "/home/username/public_html/dev/toolbar" you can use the basename function.
      [code=php]<?php
      $dir = '/home/username/public_html/dev/toolbar';
      echo basename($dir);
      // Output: toolbar
      ?>[/code]

      Comment

      • nouras
        New Member
        • Apr 2010
        • 15

        #4
        Originally posted by Atli
        Hey.

        To get only the "toolbar" part of "/home/username/public_html/dev/toolbar" you can use the basename function.
        [code=php]<?php
        $dir = '/home/username/public_html/dev/toolbar';
        echo basename($dir);
        // Output: toolbar
        ?>[/code]
        thanx Atli....

        Comment

        • gobblegob
          New Member
          • Dec 2007
          • 133

          #5
          Originally posted by Atli
          Hey.

          To get only the "toolbar" part of "/home/username/public_html/dev/toolbar" you can use the basename function.
          [code=php]<?php
          $dir = '/home/username/public_html/dev/toolbar';
          echo basename($dir);
          // Output: toolbar
          ?>[/code]
          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
          Code:
          string dirname ( string $path )
          but i dont need to now. Thank you!

          Comment

          Working...