PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Como analisar a string de pesquisa do usuário para a consulta do Postgresql?


Tente isto:
$a=array('word1 +word2','word1+word2','word1    -word2',' word1-word2','word1 word2','word1  word2');

foreach ($a as &$v) {
  $v=preg_replace('/ +/','|',        // last: change blanks to |
     preg_replace('/ *(?=[!&])/','', // delete blanks before ! or &
     strtr(trim($v),array('-'=>'&!','+'=>'&'))  // turn + and - into & and !&
     ));
}
print_r($a);

Isso dará:
Array
(
    [0] => word1&word2
    [1] => word1&word2
    [2] => word1&!word2
    [3] => word1&!word2
    [4] => word1|word2
    [5] => word1|word2
)