function views_natural_sort_remove_words in Views Natural Sort 8.2
Same name and namespace in other branches
- 7.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.
File
- ./
views_natural_sort.inc, line 47 - The Views Natural Sort module include file.
Code
function views_natural_sort_remove_words($string) {
$words = [
t('and'),
t('or'),
t('of'),
];
if (empty($words)) {
return $string;
}
array_walk($words, 'preg_quote');
return preg_replace([
'/\\s(' . implode('|', $words) . ')\\s+/i',
'/^(' . implode('|', $words) . ')\\s+/i',
], [
' ',
'',
], $string);
}