PHP function for creating URL slugs

This simple function removes every character from a string that isn’t a number or letter and replaces it with a dash. Simple, but effective and quick.

function create_slug($string) {  
    return preg_replace('/[^A-Za-z0-9-]+/', '-', $string);  

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × 3 =