Created
May 3, 2014 00:57
-
-
Save madeinnordeste/869be634977884f954b7 to your computer and use it in GitHub Desktop.
PHP - Convert string to slug
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 | |
function slug($str){ | |
$str = strtolower(trim($str)); | |
$str = preg_replace('/[^a-z0-9-]/', '-', $str); | |
$str = preg_replace('/-+/', "-", $str); | |
return $str; | |
} | |
echo slug('This is my string ;) '); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment