Create URL Slug from String

<?php
function generateSlug($string)
{
    $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
    return $slug;
}

 echo generateSlug('this is simple text');
 //returns 'this-is-simple-text'

?>

Do you find this helpful?

Related articles