You are here

function views_natural_sort_remove_beginning_words in Views Natural Sort 8.2

Same name and namespace in other branches
  1. 7.2 views_natural_sort.inc \views_natural_sort_remove_beginning_words()

Remove all the configured words from the beginning of the string only.

Parameters

string $string: The string we wish to transform.

Return value

string The transformed string.

File

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

Code

function views_natural_sort_remove_beginning_words($string) {
  $beginning_words = [
    t('The'),
    t('A'),
    t('An'),
    t('La'),
    t('Le'),
    t('Il'),
  ];
  if (empty($beginning_words)) {
    return $string;
  }
  array_walk($beginning_words, 'preg_quote');
  return preg_replace('/^(' . implode('|', $beginning_words) . ')\\s+/i', '', $string);
}