function _easy_breadcrumb_normalize_url_segment_text in Easy Breadcrumb 6
Same name and namespace in other branches
- 7 includes/easy_breadcrumb.blocks.inc \_easy_breadcrumb_normalize_url_segment_text()
Normalizes an URL segment's title. E.g., transforms "about-us" to "About Us" or "About us", according to parameters.
Parameters
string $segment: Segment's title to be normalized.
string $uppercase_mode: Specifies the type of uppercase transformation (if any) to be applied.
Return value
string normalized segment title.
1 call to _easy_breadcrumb_normalize_url_segment_text()
- _easy_breadcrumb_block in includes/
easy_breadcrumb.blocks.inc - Obtains the 'easy_breadcrumb' block.
File
- includes/
easy_breadcrumb.blocks.inc, line 152 - Module's blocks.
Code
function _easy_breadcrumb_normalize_url_segment_text($segment, $uppercase_mode = 'ucwords', $capitalizator_ignored_words = array()) {
// Transforms '-hello--world_javascript-' on 'hello world javascript'.
$normalized_segment = str_replace(array(
'-',
'_',
), ' ', $segment);
$normalized_segment = trim($normalized_segment);
$normalized_segment = preg_replace('/\\s{2,}/', ' ', $normalized_segment);
switch ($uppercase_mode) {
// Transforms the text 'once a time' to 'Once a Time'.
case 'ucwords':
$segments_arr = explode(' ', $normalized_segment);
// Transforms the non-ignored words of the segment.
$segments_arr[0] = drupal_ucfirst($segments_arr[0]);
for ($idx_1 = 1, $segments_words_quantity = count($segments_arr); $idx_1 < $segments_words_quantity; ++$idx_1) {
// Transforms this word only if it is not in the list of ignored words.
if (!isset($capitalizator_ignored_words[$segments_arr[$idx_1]])) {
$segments_arr[$idx_1] = drupal_ucfirst($segments_arr[$idx_1]);
}
}
$normalized_segment = join(' ', $segments_arr);
break;
// Transforms the text 'once a time' to 'Once a time'.
case 'ucfirst':
$normalized_segment = drupal_ucfirst($normalized_segment);
break;
default:
}
return $normalized_segment;
}