sql >> Base de Datos >  >> RDS >> PostgreSQL

¿Cómo analizar la cadena de búsqueda del usuario para la consulta de Postgresql?

Prueba esto:

$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);

Esto dará:

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