www.webdeveloper.com
Results 1 to 5 of 5

Thread: Get current directory and display in specific format.

  1. #1
    Join Date
    Aug 2008
    Posts
    17

    Get current directory and display in specific format.

    What I am try to do is create a script that will display the current folder/directory that the index.php is in, but I want the output to display in a standard format. I need to convert the underscore into a space and capatalize the first letter of each word.

    eg.
    --> files: my_folder/index.php

    --> output: My Folder

    Any thoughts?

  2. #2
    Join Date
    Jan 2006
    Posts
    21
    PHP Code:
    <?php
    //
    // Rename Directory to name
    //
    $dir basename(dirname(__FILE__));
    echo 
    ucwords(str_replace('_'' '$dir));
    ?>

  3. #3
    Join Date
    Aug 2008
    Posts
    17
    Quote Originally Posted by ElvisLives
    PHP Code:
    <?php
    //
    // Rename Directory to name
    //
    $dir basename(dirname(__FILE__));
    echo 
    ucwords(str_replace('_'' '$dir));
    ?>
    Almost there, at the moment it does the formatting fine but the script displays the location of the .php within my includes folder (instead of the actual location after processing).

    Any further ideas?

  4. #4
    Join Date
    Jun 2007
    Location
    Tangerang, Banten
    Posts
    258
    Try this code :
    PHP Code:
    <?php
    $dir 
    "/my_folder/my_folder2/test.php"//-> dummy
    preg_replace("#(?<=/)[^\/\:\*\?\\\"\<\>\|]+(?=/)#e","\$directory[]=ucwords(str_replace('_', ' ', '$0'))",$dir);
    print_r($directory);
    ?>
    It will have output :
    Array
    (
    [0] => My Folder
    [1] => My Folder2
    )
    You can modify it by yourself...
    The requirement is between / or the name of folder there is no \ / : * ? " < > | characters. This is windows style. Not test it in unix.

    Hope this helps..
    EDIT :
    if $dir is :
    Code:
    $dir = "my_folder/my_folder2/test.php";
    No / in front of it.
    You can use this :
    Code:
    preg_replace("#[^\/\:\*\?\\\"\<\>\|]+(?=/)#e","\$directory[]=ucwords(str_replace('_', ' ', '$0'))",$dir);
    That replacement will have the same output as before.
    Last edited by andre4s_y; 09-29-2008 at 11:19 AM.

  5. #5
    Join Date
    Aug 2008
    Posts
    17
    Thanks for the andre4s! I managed to alter the code you gave me to get it to do what I want. Thanks for the help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles