0
Welcome Guest! Login
0 items Join Now

Need some php help

    • Lee's Avatar

    Need some php help

    Posted 18 years 4 months ago
    • Can anyone help me with this script please
      <?php
       
           header('Content-type: text/plain');
           $search_queries = initArray();
           $query = $_GET['query'];
           $results = search($search_queries, $query);
           sendResults($query,$results);
       
      function search($search_queries, $query) {
           if (strlen($query) == 0)
                return;
       
           $query = strtolower($query);
       
           $firstChar = 0;
       
           if (!preg_match('/[0-9a-z]/',$firstChar,$matches))
                return;
       
                $charQueries = $search_queries[$firstChar];
       
           $results = array();
       
           for($i = 0; $i < count($charQueries); $i++) {
      if (strcasecmp(substr($charQueries[$i],0,strlen($query)),$query) == 0)
       
                     $results[] = $charQueries[$i];
           }
       
           return $results;
      }
       
      function sendResults($query,$results) {
           for ($i = 0; $i < count($results); $i++)
                print "$results[$i]\n";
      }
       
      function initArray() {
           return array(
           '0' => array(
      "The Ant Bully",
      "The Dog Island",
      "The Dog Island: Hitotsu no Hana no Monogatari",
      "The Grim Adventures of Billy & Mandy",
      "The Last Ninja",
      "The Legend of Zelda",
      "The Legend of Zelda: Twilight Princess",
      "The Sims",
      )
           );
      }
      ?>

      Basically it performs a search on an array. The trouble is that if the first character of my search query does not match the first character of the string in the array, I get no results. For example. Typing "the legend of zelda" returns a result. But just typing "zelda" returns no result. Anyone see why?
    • Last Edit: 18 years 4 months ago by .
    • Lee's Avatar

    Re: Need some php help

    Posted 18 years 4 months ago
    • Problem solved now.

Time to create page: 0.047 seconds