www.webdeveloper.com
Results 1 to 5 of 5

Thread: kinda uhm sorta i dunno well like

  1. #1
    Join Date
    Mar 2003
    Posts
    42

    kinda uhm sorta i dunno well like

    Hi, thanks for looking,

    Ive got for example 6 images in my folder

    12_force1.jpg
    12_fun.jpg
    13_whhaat.jpg
    13_awww.jpg
    14_somma.jpg
    14_tune.jpg

    anyways, i want a function to list the images based on the #### at the front ...

    function GetPics($ID){

    if $ID is in the name of the image
    echo

    }

    that kinda thing...I know its a stupid way to do it, and something like storing in directories would make alot more sense, but ive got some crazy permission problems with this host, and dont want to get into it ... so if anyone can help with that, id reaaaally appreciate it

    Thanks,
    Al

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Here's the logic:

    Get the name of the image, split at the _ (if this is after the number in all the images) and take the first part. If you need help, post how you are getting the images (looping though the directory and pulling all files?).

  3. #3
    Join Date
    Mar 2003
    Posts
    42
    well i would prefer to not have to arrray all the files and then sort thru them, cause it'd be quite slow ... just thought maybe PHP has something like that already ... if not maybe i can think of a different way ... i dunno

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by Bungholio
    well i would prefer to not have to arrray all the files and then sort thru them, cause it'd be quite slow ...
    Perhaps you misunderstood what pyro said:

    Originally posted by pyro
    If you need help, post how you are getting the images (looping though the directory and pulling all files?).
    Notice the phrase in the parenthesis. What he's saying is, read the contents (files) of the directory, and fill them into an array automatically, then loop through each one and split it at the underscore (_); and return the two characters (digits) before it.

    Just a BTW thing, pyro, is there an alternate way to use split? Normally I use the list() function like this:


    PHP Code:
    $str "abc_cba";
    list(
    $a$b) = split("_"$str);
    echo (
    "$a<br>\n$b"); 
    [Jona]

  5. #5
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Jona -

    Yeah, you can do something like this, though using list is fine.

    PHP Code:
    <?PHP
    $img 
    "10_image.gif";
    $array split("_",$img); #will turn $array into an array of the split items.
    echo $array[0];
    ?>
    Bungholio -

    You can use a script like this to get all the files out of the directory, and then use something like the above to split it up...

    PHP Code:
    $handle opendir($folder); #opens the directory so we can read the files out
    while ($file readdir($handle)) { #loop through the files
        
    $array[] = $file#make an array of the files
    }
    closedir($handle); #close the directory 

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