-
-
Save alexdumont/addedecf40839516ba6b to your computer and use it in GitHub Desktop.
Function which create a slug from string
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($str, $delimiter='-', $charset='utf-8') { | |
| $str = preg_replace("`\[.*\]`U","",$str); | |
| $str = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$str); | |
| $str = htmlentities($str, ENT_NOQUOTES, $charset); | |
| $str = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i","\\1", $str ); | |
| $str = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $str); | |
| $str = ( $str == "" ) ? $type : strtolower(trim($str, '-')); | |
| $str = strtolower($str); | |
| return $str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment