Skip to content

Instantly share code, notes, and snippets.

@ntulip
Created July 6, 2011 18:11
Show Gist options
  • Save ntulip/1067915 to your computer and use it in GitHub Desktop.
Save ntulip/1067915 to your computer and use it in GitHub Desktop.
slug.php
/*
* http://necenzurat.net/2010/05/26/clean-up-and-url-like-wordpress-does.dev
* Create a slug for friendly URL's a-la wordpress
*/
function clean_url($str) {
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
return $clean;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment