« Previous entry | Next entry » Browse > Snippets

Skip to comments (2) search query generator
Posted by Erik on Oct 15 2005 @ 19:42  :: 1578 unique visits

This is a simple search query generator which supports the following things:

CODE: PHP
$search   = $_GET['search'];
$searchon = '';
$inquotes = false;
$slash    = false;

for ($i = 0; $i < strlen($search); $i++) {
  switch ($search[$i]) {
    case '\\':
      if ($search[$i+1] == '\\')
        $searchon .= '\\';
      break;
    case '"':
      $inquotes = !$inquotes;
      break;
    case ' ':
      if ($inquotes)
        $searchon .= ' ';
      else
        $searchon .= '%';
      break;
    case '*';
      $searchon .= '%';
      break;
    case '.';
      $searchon .= '_';
      break;
    default:
      $searchon .= $search[$i];
      break;
  }
}

// now in the query:  'WHERE text LIKE "'.$searchon.'"'
 

2 comments posted so far
Add your own »

1. On May 13 2009 @ 15:47 guest wrote:

Need Furniture? And need to buy furniture from China at competitive price? LongYear Furniture is your source for quality bedroom furniture featuring a huge selection of home furniture a happy home for beautiful life, kids furniture for a good memory of childhood, and to gain an extra good price from wholesale furniture and direct from  furniture manufacturers China, styles of China furniture are available, living room furniture is also nice for your house, find dining room furniture and more!

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: