Created
April 2, 2017 09:04
-
-
Save rajbdilip/2bbf6ce2d977a06a70d127b7d718a971 to your computer and use it in GitHub Desktop.
Generate clean URL (slug) from a string
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 | |
/** | |
* Generates clean URL | |
* | |
* @param string | |
* @return string | |
*/ | |
function slugify( $string ) { | |
$cleanString = preg_replace( "/[^a-zA-Z0-9\/_|+ -]/", '', $string ); | |
$cleanString = strtolower( trim( $cleanString, '-' ) ); | |
$cleanString = preg_replace( "/[\/_|+ -]+/", '-', $cleanString ); | |
return $cleanString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment