Skip to content

Instantly share code, notes, and snippets.

@anunay
Created June 12, 2013 22:58
Show Gist options
  • Save anunay/5769861 to your computer and use it in GitHub Desktop.
Save anunay/5769861 to your computer and use it in GitHub Desktop.
PHP Convert String to Slug
<?php
function to_slug($string){
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
}
// Input: This is Headline
// Returns: this-is-headline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment