You are here

public static function SuggestionHelper::tokenize in Autocomplete Search Suggestions 8

Same name and namespace in other branches
  1. 8.2 src/SuggestionHelper.php \Drupal\suggestion\SuggestionHelper::tokenize()
  2. 3.0.x src/SuggestionHelper.php \Drupal\suggestion\SuggestionHelper::tokenize()

Tokenize the text into space separated lowercase strings.

Parameters

string $txt: The text to process.

int $min: The minimum number of characters in a token.

Return value

string The tokenized string.

3 calls to SuggestionHelper::tokenize()
SuggestionAdminForm::setStopwords in src/Form/SuggestionAdminForm.php
Process all the stopwords submitted.
SuggestionHelper::insert in src/SuggestionHelper.php
Add a suggestion.
suggestion_surfer_submit in ./suggestion.module
Custom submit function to add surfer suggestions.

File

src/SuggestionHelper.php, line 313

Class

SuggestionHelper
Provides helper methods for suggestions.

Namespace

Drupal\suggestion

Code

public static function tokenize($txt = '', $min = 4) {
  $min--;
  $regx = [
    '/[^a-z]+/s' => ' ',
    '/\\b(\\w{1,' . $min . '})\\b/s' => '',
    '/\\s\\s+/s' => ' ',
    '/^\\s+|\\s+$/s' => '',
  ];
  return preg_replace(array_keys($regx), array_values($regx), strtolower(trim($txt)));
}