Last active
December 7, 2021 09:54
-
-
Save dev-jaydeep/797033da1a4ff395c579a1f537ea6797 to your computer and use it in GitHub Desktop.
create a slug from text using php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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