Skip to content

Instantly share code, notes, and snippets.

@mattkirwan
Last active December 16, 2015 09:38
Show Gist options
  • Save mattkirwan/5413844 to your computer and use it in GitHub Desktop.
Save mattkirwan/5413844 to your computer and use it in GitHub Desktop.
A quick function to create a url 'slug' from a given string.
<?php
function convertToSlug($input)
{
$text = preg_replace('~[^\\pL\d]+~u', '-', $input);
$text = trim($text, '-');
$text = strtolower($text);
$text = preg_replace('~[^-\w]+~', '', $text);
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment