Created
February 21, 2014 09:59
-
-
Save LiamChapman/9131672 to your computer and use it in GitHub Desktop.
Small function for creating "slugs" or URI in PHP
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 | |
| if (!function_exists('slugify')) { | |
| function slugify ($str, $replace="-") { | |
| // replace all non letters or digits by $replace | |
| $str = preg_replace('/\W+/', $replace, $str); | |
| // trim and lowercase | |
| $str = strtolower(trim($str, $replace)); | |
| return $str; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment