function nodewords_unique_values in Nodewords: D6 Meta Tags 6
Same name and namespace in other branches
- 6.3 nodewords.module \nodewords_unique_values()
- 6.2 nodewords.module \nodewords_unique_values()
Remove the duplicates from a list of items separated from the separator, preserving the order in which they appear.
Parameters
$text: The string containing the list of items concatenated using $separator.
$separator: The string used to split the string into an array. A space will be appended to the string before it is used to create the string from the array of unique items found in the string passed as argument.
$max_items: The maximum number of items accepted in the returned array; the default value is -1, which means no limit.
Return value
A string containing only unique items present in the string of concatenated items.
2 calls to nodewords_unique_values()
- nodewords_basic_keywords_prepare in nodewords_basic/
nodewords_basic.module - Set the meta tag content.
- nodewords_update_6102 in ./
nodewords.install - Implements hook_update_N().
File
- ./
nodewords.module, line 1190 - Implement an API that other modules can use to implement meta tags.
Code
function nodewords_unique_values($text, $separator = ',', $max_items = -1) {
$lc_values = array();
$unique_values = array();
if (empty($text)) {
return '';
}
foreach (array_filter(array_map('trim', explode($separator, $text))) as $item) {
$lowercase = drupal_strtolower($item);
if (!in_array($lowercase, $lc_values)) {
$lc_values[] = $lowercase;
$unique_values[] = $item;
}
}
if ($max_items > 0) {
$unique_values = array_slice($unique_values, 0, $max_items);
}
return implode("{$separator}", $unique_values);
}