Results 1 to 4 of 4

Thread: Search Directory

  1. #1
    Join Date
    Aug 2009
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Search Directory

    I need help.... Ugh Alright ive got this code

    PHP Code:
    <?php
    if ($handle opendir('./')) {
    while (
    false !== ($file readdir($handle))) {
    $filesplit explode("."$file);
    $check $filesplit[0];
    $keyword=$_GET['search'];

    if(
    ereg($keyword$check))
    {
    $check .= ".$filesplit[1]";
    $valid[] = $check;

    }
    }

    echo 
    "Search Term: <i>$keyword</i> - <BR>";
    for(
    $index 0$index count($valid); $index++)
    {

    echo
    "<font size=2> <A href='$valid[$index]'>$valid[$index]</a></font><BR>";
    }
    closedir($handle);

    }
    ?>
    What this does is it searches my directory for what ever keyword is put in but..

    If i have an item in my directory called " Music " and i type in " music " with a lower case m nothing shows, so how would i make it non case sensitive?

    That way i can look up Music or music and it'll show.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The easiest way to deal with issues of capitals and lowercase is to force all strings to be one or the other.
    strtolower() will take any string ("Music", "music") and output only lowercase ("music" for both). (strtoupper() exists too, if you'd rather use that.)
    That way you can match everything.
    Remember to apply the function to both things you are comparing (the search phrase and the filenames).

    There are also some other functions that deal with this, like array sorting functions that ignore case, but that's probably beyond what you need here.

    Hope this gets you started.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2009
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Alright but when i upload files into a directory say i upload a file named ' Music001.mp3 ' useing my FTP program how would i make that work?

    I've got the strtolower working but its not reading my file cause its an uppercase M in the directory.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I never use uppercase letters in my web directories or filenames (or just about anywhere else, if I can avoid it) for just that reason.

    for example, this will work on some webhosts, but not others:
    html:
    Code:
    <img src="picture.jpg">
    filename on server:
    Code:
    picture.JPG

Bookmarks

Posting Permissions

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