1 path.inc | _path_clean_separators($string, $separator = NULL) |
Trims duplicate, leading, and trailing separators from a string.
Parameters
$string: The string to clean path separators from.
$separator: The path separator to use when cleaning.
Return value
The cleaned version of the string.:
See also
File
- core/
modules/ path/ path.inc, line 264 - Miscellaneous functions for Path module.
Code
function _path_clean_separators($string, $separator = NULL) {
$config = config('path.settings');
static $default_separator;
if (!isset($separator)) {
if (!isset($default_separator)) {
$default_separator = $config->get('separator');
}
$separator = $default_separator;
}
$output = $string;
if (strlen($separator)) {
// Trim any leading or trailing separators.
$output = trim($output, $separator);
// Escape the separator for use in regular expressions.
$seppattern = preg_quote($separator, '/');
// Replace multiple separators with a single one.
$output = preg_replace("/$seppattern+/", $separator, $output);
// Replace trailing separators around slashes.
if ($separator !== '/') {
$output = preg_replace("/\/+$seppattern\/+|$seppattern\/+|\/+$seppattern/", "/", $output);
}
}
return $output;
}