I think the title is pretty explanatory. I have a custom table in which i retrieve human readable titles in 'title'. This title could be any language, and since i'm french it could have accents for instance. I would like to change a title like : "L'océan indien, l'Asie et la végétation" into the 'cleanurl' field : "l-ocean-indien-l-asie-et-la-vegetation".

I've seen this topic that seemed interesting, but neither machine name nor safeword seems to be usable with transliterate (or i don't see how).

I've tried some "custom" function but does not work completely as expected (and is not a serious replacement for transliterate i guess :

function clean_name($string)
  $string = html_entity_decode($string);
  $string = str_replace(''', '\'', trim(strtolower($string)));
  $search  = 'àáâãäåçèéêëìíîïðòóôõöùúûüýÿ';
  $replace = 'aaaaaaceeeeiiiioooooouuuuyy';
  $string = strtr($string, $search, $replace);
  $string = preg_replace('/[^a-z0-9-]/', '-', $string);
  $string = trim($string, '-');
  $string = preg_replace('/-{2,}/', '-', $string);
  return $string;

What can you suggest to achieve this goal ? I would obviously prefer to use core functions if possible.

EDIT -- @Clive I tried to use the pathauto/transliteration modules and i've manage to get what i want, but i'm not sure this is the right way.

module_load_include('inc', 'pathauto', 'pathauto');
module_load_include('module', 'transliteration', 'transliteration');
$cleantitle = pathauto_cleanstring(transliteration_get($string));

This might not be the optimal way since as you emphasised : Process the string through the transliteration module, but i'm not at ease enough with Drupal code. From the code in pathauto_cleanstring(), transliteration_get should be processed automatically if

variable_get('pathauto_transliterate', FALSE) && module_exists('transliteration')

Both are enabled in my Drupal, but if i do pathauto_cleanstring($string); the transliteration is not aplied.

But again, if nobody tells me why, this works with pathauto_cleanstring(transliteration_get($string));


I don't think core has any such function, but the Pathauto module does.


Clean up a string segment to be used in an URL alias.

Performs the following possible alterations:

  • Remove all HTML tags.
  • Process the string through the transliteration module.
  • Replace or remove punctuation with the separator character.
  • Remove back-slashes.
  • Replace non-ascii and non-numeric characters with the separator.
  • Remove common words.
  • Replace whitespace with the separator character.
  • Trim duplicate, leading, and trailing separators.
  • Convert to lower-case.
  • Shorten to a desired length and logical position based on word boundaries.

Emphasis mine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.