PHP Eliminar las palabras de parada de la cadena
public function optimizeSearchString($searchString = "")
{
$stopwords = array(
'der' => 1,
'die' => 1,
'das' => 1,
'the' => 1);
$words = preg_split('/[^-\w\']+/', $searchString, -1, PREG_SPLIT_NO_EMPTY);
if (count($words) > 1) {
$words = array_filter($words, function ($v) use (&$stopwords) {
return !isset($stopwords[strtolower($v)]);
}
);
}
if (empty($words)) {
return $searchString;
}
return implode(" ", $words);
}
Geeky Bravo