Skip to content

Instantly share code, notes, and snippets.

@rajbdilip
Created April 2, 2017 09:04
Show Gist options
  • Save rajbdilip/2bbf6ce2d977a06a70d127b7d718a971 to your computer and use it in GitHub Desktop.
Save rajbdilip/2bbf6ce2d977a06a70d127b7d718a971 to your computer and use it in GitHub Desktop.
Generate clean URL (slug) from a string
<?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