Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    removing the "." and ".." when using opendir

    I currently have a script to list the folders inside of the images folder in a select box. the output source is this:
    Code:
    <select>
    <option value="">Select an Album</option>
    <option value=".">.</option>
    <option value="..">..</option>
    <option value="test">test</option>
    <option value="test2">test2</option>
    </select>
    PHP Code:
    <select    name="album">
    <option value="">Select an Album</option>
    <?
    $path 
    "images/";
    $dir_handle = @opendir($path) or die("Unable to open $path");

    while(
    $file readdir($dir_handle)) {
        echo 
    "<option value=\"$file\">$file</option>";
    }
    ?>
    is there any way to get rid of the <option value=".">.</option><option value="..">..</option>
    Last edited by mhunt; 03-08-2007 at 08:34 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could use regex providing there isn't going to be a dot in the other options. My regex isn't great but I think it's something like the following:

    PHP Code:
    while($file readdir($dir_handle)) 
    {
        if(!
    preg_match("/\./"$file))
        {
           echo 
    "<option value=\"$file\">$file</option>";
        }

    Alex
    Give me Rep if I was helpful and ignore if I wasn't ;)

    http://www.google.com <--use this before asking

    Nominate a Helpful Member


  • #3
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    /\.\.?/
    will match both . and ..

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    haha sweet that worked

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad to hear. And does

    Code:
    /\.+/
    match a dot any number of times?

    Alex
    Give me Rep if I was helpful and ignore if I wasn't ;)

    http://www.google.com <--use this before asking

    Nominate a Helpful Member



  •  

    Posting Permissions

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