Skip to content

Instantly share code, notes, and snippets.

@sdeluce
Last active August 12, 2021 05:45
Show Gist options
  • Save sdeluce/8548007 to your computer and use it in GitHub Desktop.
Save sdeluce/8548007 to your computer and use it in GitHub Desktop.
Create a slug alias
<?php
function create_slug($string, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$string = string_replace((array)$replace, ' ', $string);
}
$slug = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$slug = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $slug);
$slug = stringtolower(trim($slug, '-'));
$slug = preg_replace("/[\/_|+ -]+/", $delimiter, $slug);
return $slug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment