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 3 of 3

Thread: Edit an array

  1. #1
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Edit an array

    I have an array that is all the files in a directory.
    PHP Code:
    <?php
    $dir 
    "../images/galleries/";
    $dh  opendir($dir);
    while (
    false !== ($filename readdir($dh))) {
       
    $files[] = $filename;
    }
    sort($files);
    print_r($files);
    ?>
    How would I
    -Strip off the . and the .. at the begining
    -Make it so that I can turn each one of them into a different link
    I used to be great at this stuff, but its been awhile...

    Thanks,
    Adam
    Why not thank me?

    http://adamsworld.name

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,071
    Thanks
    11
    Thanked 96 Times in 94 Posts
    I prefer glob...
    PHP Code:
    <?php
    $dir 
    "../images/galleries/";
    $files  glob($dir.'*.*');
    //sort($files);
    foreach($files as $f){
        echo 
    '<a href="'.$f.'">'.basename($f).'</a><br />';
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Thanks man works great. Also now I can have it return only folders or files.
    I dont think ive ever used glob before... Ill go read up on it.

    -Adam
    Why not thank me?

    http://adamsworld.name


  •  

    Posting Permissions

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