Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php remove stop words from string

  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);
  }
Comment

PREVIOUS NEXT
Code Example
Php :: php number format 
Php :: increase memory limit wordpress 
Php :: Laravel Password & Password_Confirmation Validation 
Php :: php get current month first date 
Php :: Excerpt/ get post content 
Php :: target class usercontroller does not exist. in laravel 8 
Php :: array reduce associative array php 
Php :: E: Unable to locate package php8.0 
Php :: how validate array in laravel in request 
Php :: 404 page in laravel 
Php :: how to create wordpress shortcodes 
Php :: PHP substr_count — Count the number of substring occurrences 
Php :: creer un modele laravel 
Php :: mpdf output 
Php :: csv file to associative array php 
Php :: get taxonomy term meta by id 
Php :: install php-8 
Php :: db raw update laravel 
Php :: Composer Fatal error: Call to undefined function SymfonyPolyfillMbstringiconv() in phar 
Php :: php array map cast to int 
Php :: regex php password 
Php :: wordpress add_submenu_page 
Php :: symfony doctrine existing database 
Php :: php return json data to ajax 
Php :: wordpress change language of specific text php 
Php :: laravel task scheduling command 
Php :: what is scalar data type in php 
Php :: how to get parameter from url in laravel blade 
Php :: catch any exception php 
Php :: laravel-medialibrary packagist 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =