string comparison

Discussion in 'PHP' started by sudhakararaog, Jul 14, 2008.

  1. #1
    hi

    i am writing a small application where a user enters a phrase in the textfield and i would like to display all the files present in the root directory which consists of the keyword or keywords entered by the user.

    i have used a few comparison functions but i am not getting the expected result.

    $my_file = file_get_contents("filename.html");
    what ever the user enters whether it is a single word or few words i would like to compare with $my_file in a case insensitive manner.

    can anyone suggest the best method and how to go about.

    thanks.
     
    sudhakararaog, Jul 14, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    stristr is your requested object, or preg_match, try php.net for more info about those functions
     
    EricBruggema, Jul 14, 2008 IP
  3. revvi

    revvi Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The concept is like this:

    $my_file = file_get_contents("filename.html");
    $my_array = explode($my_file, ' ');
    
    // i haven't go through with correct function
    // convert all values in array to lowercase, because you need case insensitive
    $new_array = array();
    foreach ($my_array as $value) {
    $new_array[] = strtolower($value);
    }
    
    // compare user input case insensitive style
    if (in_array(strtolower($your_user_input), $new_array) {
    echo "Found";
    } else {
    echo "Not found";
    }
    PHP:
    Sorry I haven't further tested this as I don't have my eclipse in front of me :).
    I hope this helps a bit.
     
    revvi, Jul 14, 2008 IP