Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Created February 21, 2014 09:59
Show Gist options
  • Select an option

  • Save LiamChapman/9131672 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/9131672 to your computer and use it in GitHub Desktop.
Small function for creating "slugs" or URI in PHP
<?php
if (!function_exists('slugify')) {
function slugify ($str, $replace="-") {
// replace all non letters or digits by $replace
$str = preg_replace('/\W+/', $replace, $str);
// trim and lowercase
$str = strtolower(trim($str, $replace));
return $str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment