| 1 system.module |
system_transliterate_machine_name($string, $options = array()) |
File
- core/modules/system/system.module, line 4847
- Configuration system that lets administrators modify the workings of the site.
Code
function system_transliterate_machine_name($string, $options = array()) {
include_once BACKDROP_ROOT . '/core/includes/transliteration.inc';
$defaults = array(
'langcode' => $GLOBALS['language']->langcode,
'replace' => '_',
'replace_pattern' => NULL,
'maxlength' => NULL,
);
$options = array_intersect_key($options, $defaults) + $defaults;
if (!isset($options['replace_pattern'])) {
$options['replace_pattern'] = '[^0-9A-Za-z' . $options['replace'] . ']+';
}
$replace = $options['replace'];
$string = transliteration_get($string, $replace, $options['langcode']);
if ($options['replace_pattern']) {
$string = preg_replace('/' . $options['replace_pattern'] . '/', $options['replace'], $string);
}
$string = str_replace(' ', $replace, $string);
$string = trim($string, $replace);
$replace_regex = strlen($replace) ? "([$replace])[$replace]+|" : '';
$string = preg_replace("/{$replace_regex}(_)_+|(\\.)\\.+|(-)-+/", '$1$2$3$4$5', $string);
if ($options['maxlength']) {
$string = substr($string, 0, $options['maxlength']);
}
return $string;
}