I need to convert the title of a node, for example, from this
John Doe
to
john-doe
Is there Drupal function for it? (Easier to use than using preg_preplace etc.)
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI need to convert the title of a node, for example, from this
John Doe
to
john-doe
Is there Drupal function for it? (Easier to use than using preg_preplace etc.)
If you're just looking for a way to convert the title into a URL friendly machine name, then the following regex will do what you need:
$machine_name = preg_replace('@[^a-z0-9-]+@','-', strtolower($title));
If you are on the node template (ie. node.tpl.php), you should have $node->nid
available.
drupal_html_class($class)
function in core. – milkovsky Sep 3 '14 at 10:52