Question : php remove stop words from string
Answered by : geeky-bravo
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); }
Source : https://stackoverflow.com/questions/32310787/remove-stop-words-from-searchstring-in-php | Last Update : Wed, 09 Sep 20