Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 0.95 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Non alphanumeric characters replaced with a single space
  2. $sql_where = array();
  3.  
  4. if (isset($_GET['name'])) {
  5.  
  6.     echo "Searched: {$_GET['name']}<br>";
  7.  
  8.     $names = explode(' ', trim(preg_replace('/ +/', ' ', $_GET['name'])));
  9.     $names_cnt = count($names);
  10.  
  11.     if (2 == $names_cnt) {
  12.  
  13.         foreach ($names as $name_idx => $name) {
  14.  
  15.             if (($name_idx+1) == $names_cnt) {
  16.                 // last one
  17.                 $sql_where[] = "
  18.                     (full_name like '% {$name}%')
  19.                     ";
  20.             } else {
  21.                 // first one
  22.                 $sql_where[] = "
  23.                     (full_name like '{$name}%')
  24.                     ";
  25.             }
  26.         }
  27.     } else {
  28.  
  29.         $sql_where[] = "
  30.             (full_name like '" . $DB->cleanString($_GET['name']) . "%')
  31.             ";
  32.        
  33. echo preg_replace( "`[^a-zA-Z0-9]+`", " ", $string);
  34. //replaces all non alpha numeric characters as " "
  35. //(and will not have duplicate spaces)