title: Remove stop words from searchstring in PHP
body: <p>I am facing problems with a PHP function for optimizing a search string for a MySql query.</p>
  <p>I need to find an entry which look like 'hobbit, the' by searching for 'the hobbit'.</p>
  <p>I thought about cutting the articles (in Germany we have 'der', 'die' and 'das') if they have a trailing space out of the search string.</p>
  <p>My function looks like:</p>
  <pre><code>      public function optimizeSearchString($searchString)
        {
          $articles = [
            'der ',
            'die ',
            'das ',
            'the '
          ];
      
      
          foreach ($articles as $article) {
  //only cut $article out of $searchString if its longer than the $article itself
            if (strlen($searchString) &gt; strlen($article) &amp;&amp; strpos($searchString, $article)) {
              $searchString = str_replace($article, '', $searchString);
              break;
            }
          }
      
          return $searchString;
        }
  </code></pre>
  <p>But this doesn't work...</p>
  <p>Maybe there is a nicer solution using regular expressions?</p>