1 path.inc | path_clean_alias($alias) |
Clean up a URL alias.
Performs the following alterations:
- Trim duplicate, leading, and trailing back-slashes.
- Trim duplicate, leading, and trailing separators.
- Shorten to a desired length and logical position based on word boundaries.
Parameters
string $alias: A string with the URL alias to clean up.
Return value
string: The cleaned URL alias.
File
- core/
modules/ path/ path.inc, line 309 - Miscellaneous functions for Path module.
Code
function path_clean_alias($alias) {
$config = config('path.settings');
$cache = &backdrop_static(__FUNCTION__);
if (!isset($cache)) {
$cache = array(
'maxlength' => min($config->get('max_length'), _path_get_schema_alias_maxlength()),
);
}
$output = $alias;
// Trim duplicate, leading, and trailing separators. Do this before cleaning
// backslashes since a pattern like "[token1]/[token2]-[token3]/[token4]"
// could end up like "value1/-/value2" and if backslashes were cleaned first
// this would result in a duplicate backslash.
$output = _path_clean_separators($output);
// Trim duplicate, leading, and trailing backslashes.
$output = _path_clean_separators($output, '/');
// Shorten to a logical place based on word boundaries.
$output = truncate_utf8($output, $cache['maxlength'], TRUE);
return $output;
}