Skip to content

Instantly share code, notes, and snippets.

@luisdalmolin
Created March 15, 2013 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisdalmolin/5172707 to your computer and use it in GitHub Desktop.
Save luisdalmolin/5172707 to your computer and use it in GitHub Desktop.
<?php
class Slug
{
/**
* Create a URI friendly slug from a string.
*
* @param string $uri
* @return string
*/
public static function make($uri)
{
$uri = iconv('UTF-8', 'ASCII//TRANSLIT', $uri);
$uri = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", null, $uri);
$uri = strtolower(trim($uri, '-'));
$uri = preg_replace("/[\/_|+ -]+/", '-', $uri);
return $uri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment