Created
August 21, 2017 07:14
-
-
Save sebgates/3224acc2f797b3c0b113ba8095e028fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| function slug($text){ | |
| // replace non letter or digits by - | |
| $text = preg_replace('~[^pLd]+~u', '-', $text); | |
| // trim | |
| $text = trim($text, '-'); | |
| // transliterate | |
| $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); | |
| // lowercase | |
| $text = strtolower($text); | |
| // remove unwanted characters | |
| $text = preg_replace('~[^-w]+~', '', $text); | |
| if (empty($text)) | |
| { | |
| return 'n-a'; | |
| } | |
| return $text; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment