Skip to content

Instantly share code, notes, and snippets.

@dev-jaydeep
Last active December 7, 2021 09:54
Show Gist options
  • Save dev-jaydeep/797033da1a4ff395c579a1f537ea6797 to your computer and use it in GitHub Desktop.
Save dev-jaydeep/797033da1a4ff395c579a1f537ea6797 to your computer and use it in GitHub Desktop.
create a slug from text using php
<?php
/**
* _slug
*
* @param mixed $str
* @param mixed $delimiter
* @return void
*/
function _slug($str, $delimiter = '-') {
return 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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment