You are here

function views_natural_sort_remove_words in Views Natural Sort 7.2

Same name and namespace in other branches
  1. 8.2 views_natural_sort.inc \views_natural_sort_remove_words()

Remove all the configured words from the string.

Parameters

string $string: The string we wish to transform.

Return value

string The transformed string.

1 string reference to 'views_natural_sort_remove_words'
views_natural_sort_get_transformations in ./views_natural_sort.module
Get the full list of transformations to run when saving a natural sort entry.

File

./views_natural_sort.inc, line 40
The Views Natural Sort module include file.

Code

function views_natural_sort_remove_words($string) {
  $words = variable_get('views_natural_sort_words_remove', array());
  if (empty($words)) {
    return $string;
  }
  array_walk($words, 'preg_quote');
  return preg_replace(array(
    '/\\s(' . implode('|', $words) . ')\\s+/iu',
    '/^(' . implode('|', $words) . ')\\s+/iu',
  ), array(
    ' ',
    '',
  ), $string);
}