Skip to content

Instantly share code, notes, and snippets.

@omedale
Created May 13, 2019 08:54
Show Gist options
  • Save omedale/2b2c66fc5050b9bc580697771ac72b3d to your computer and use it in GitHub Desktop.
Save omedale/2b2c66fc5050b9bc580697771ac72b3d to your computer and use it in GitHub Desktop.
Generate slug
public static function createSlug($str, $delimiter = '-'){
$slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter));
return $slug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment