PHP- Create slug from string

Below is simple function to slug from string.

Code

function create_slug($string){
   $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
   return $slug;
}
echo create_slug('does this thing work or not');
//returns 'does-this-thing-work-or-not'

Output

does-this-thing-work-or-not

No comments:

Post a Comment